public static DateTimeEx GetDateTimeValue(this ICdlValueReader reader) { switch (reader.GetFieldType()) { case TypeStorage.DateEx: return(new DateTimeEx { DatePart = reader.GetDateEx() }); case TypeStorage.TimeEx: return(new DateTimeEx { TimePart = reader.GetTimeEx() }); case TypeStorage.DateTime: return(new DateTimeEx { AsDateTime = reader.GetDateTime() }); case TypeStorage.DateTimeEx: return(reader.GetDateTimeEx()); default: return(new DateTimeEx()); } }
public void ConvertValue(ICdlValueReader reader, TypeStorage dsttype, ICdlValueWriter 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 SetValue(int colindex, ICdlValueReader reader) { var holder = new CdlValueHolder(); m_table.CdlConvertor.ConvertValue(reader, GetDefaultStorage(colindex), holder); m_fields[colindex].Value = holder.GetValue(); m_fields[colindex].Changed = true; if (RowState == CdlRowState.Unchanged) { RowState = CdlRowState.Modified; } }
public void AdaptValue(ICdlValueReader reader, DbTypeBase type, ICdlValueWriter writer, ICdlValueConvertor converter) { if (reader.GetFieldType() == TypeStorage.Null) { m_holder.SetNull(); } else { ConvertNotNullValue(reader, type, m_holder, converter); ApplyTypeRestrictions(m_holder, type); } writer.ReadFrom(m_holder); }
public static long GetIntegerValue(this ICdlValueReader reader) { switch (reader.GetFieldType()) { case TypeStorage.Byte: return(reader.GetByte()); case TypeStorage.Int16: return(reader.GetInt16()); case TypeStorage.Int32: return(reader.GetInt32()); case TypeStorage.Int64: return(reader.GetInt64()); case TypeStorage.SByte: return(reader.GetSByte()); case TypeStorage.UInt16: return(reader.GetUInt16()); case TypeStorage.UInt32: return(reader.GetUInt32()); case TypeStorage.UInt64: unchecked { return((long)reader.GetUInt64()); } case TypeStorage.Float: return((long)reader.GetFloat()); case TypeStorage.Double: return((long)reader.GetDouble()); case TypeStorage.Decimal: return((long)reader.GetDecimal()); default: return(0); } }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader, DbTypeBase dsttype) { if (props.BinaryStrings) { switch (reader.GetFieldType()) { case TypeStorage.String: if (props.BinaryStrings) { return dda.GetSqlLiteral(props.RealBinaryEncoding.GetBytes(reader.GetString()), dsttype); } break; } } return dda.GetSqlLiteral(reader, dsttype); }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader) { return GetSqlLiteral(props, dda, state, reader, null); }
public static void GetValueAsSqlLiteral(ICdlValueReader rec, out string sqldata) { var type = rec.GetFieldType(); if (type == TypeStorage.Null) { sqldata = "null"; return; } switch (type) { case TypeStorage.Boolean: sqldata = rec.GetBoolean() ? "1" : "0"; break; case TypeStorage.Byte: sqldata = rec.GetByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int16: sqldata = rec.GetInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int32: sqldata = rec.GetInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int64: sqldata = rec.GetInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.SByte: sqldata = rec.GetSByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt16: sqldata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt32: sqldata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt64: sqldata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.DateTime: sqldata = "'" + StringTool.DateTimeToIsoStringExact(rec.GetDateTime()) + "'"; break; case TypeStorage.DateTimeEx: sqldata = "'" + rec.GetDateTimeEx().ToStringNormalized() + "'"; break; case TypeStorage.DateEx: sqldata = "'" + rec.GetDateEx().ToStringNormalized() + "'"; break; case TypeStorage.TimeEx: sqldata = "'" + rec.GetTimeEx().ToStringNormalized() + "'"; break; case TypeStorage.Decimal: sqldata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Float: sqldata = rec.GetFloat().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Double: sqldata = rec.GetDouble().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.String: sqldata = "'" + rec.GetString().Replace("'", "''") + "'"; break; case TypeStorage.Guid: sqldata = "'" + rec.GetGuid().ToString() + "'"; break; case TypeStorage.ByteArray: { byte[] data = rec.GetByteArray(); sqldata = "X'" + StringTool.EncodeHex(data) + "'"; } break; //case TypeStorage.Array: // { // xtype = "array"; // xdata = CdlArray.ToString(rec.GetArray()); // } // break; default: throw new Exception("DBSH-00166 Unsupported field type:" + type.ToString()); } }
public static bool GetValueAsXml(ICdlValueReader rec, ref string xtype, ref string xdata) { var type = rec.GetFieldType(); if (type == TypeStorage.Null) return false; switch (type) { case TypeStorage.Boolean: xtype = "bool"; xdata = rec.GetBoolean() ? "1" : "0"; break; case TypeStorage.Byte: xtype = "byte"; xdata = rec.GetByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int16: xtype = "i16"; xdata = rec.GetInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int32: xtype = "i32"; xdata = rec.GetInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int64: xtype = "i64"; xdata = rec.GetInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.SByte: xtype = "sbyte"; xdata = rec.GetSByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt16: xtype = "u16"; xdata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt32: xtype = "u32"; xdata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt64: xtype = "u64"; xdata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.DateTime: xtype = "datetime"; xdata = rec.GetDateTime().ToString("s", CultureInfo.InvariantCulture); break; case TypeStorage.DateTimeEx: xtype = "dtex"; xdata = rec.GetDateTimeEx().ToStringNormalized(); break; case TypeStorage.DateEx: xtype = "date"; xdata = rec.GetDateEx().ToStringNormalized(); break; case TypeStorage.TimeEx: xtype = "time"; xdata = rec.GetTimeEx().ToStringNormalized(); break; case TypeStorage.Decimal: xtype = "decimal"; xdata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Float: xtype = "float"; xdata = rec.GetFloat().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Double: xtype = "double"; xdata = rec.GetDouble().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.String: xtype = "str"; xdata = rec.GetString(); break; case TypeStorage.Guid: xtype = "guid"; xdata = rec.GetGuid().ToString(); break; case TypeStorage.ByteArray: { xtype = "blob"; byte[] data = rec.GetByteArray(); xdata = Convert.ToBase64String(data); } break; //case TypeStorage.Array: // { // xtype = "array"; // xdata = CdlArray.ToString(rec.GetArray()); // } // break; } return true; }
public static void ReadFrom(this ICdlValueWriter writer, ICdlValueReader reader) { reader.WriteTo(writer); }
protected virtual void ConvertNotNullValue(ICdlValueReader reader, DbTypeBase type, CdlValueHolder valueHolder, ICdlValueConvertor converter) { converter.ConvertValue(reader, type.DefaultStorage, valueHolder); }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader) { return(GetSqlLiteral(props, dda, state, reader, null)); }
public static object BoxTypedValue(this ICdlValueReader reader) { switch (reader.GetFieldType()) { case TypeStorage.Null: return(null); case TypeStorage.Boolean: return(reader.GetBoolean()); case TypeStorage.Byte: return(reader.GetByte()); case TypeStorage.Int16: return(reader.GetInt16()); case TypeStorage.Int32: return(reader.GetInt32()); case TypeStorage.Int64: return(reader.GetInt64()); case TypeStorage.SByte: return(reader.GetSByte()); case TypeStorage.UInt16: return(reader.GetUInt16()); case TypeStorage.UInt32: return(reader.GetUInt32()); case TypeStorage.UInt64: return(reader.GetUInt64()); case TypeStorage.Float: return(reader.GetFloat()); case TypeStorage.Double: return(reader.GetDouble()); case TypeStorage.Decimal: return(reader.GetDecimal()); case TypeStorage.DateTime: return(reader.GetDateTime()); case TypeStorage.DateTimeEx: return(reader.GetDateTimeEx()); case TypeStorage.DateEx: return(reader.GetDateEx()); case TypeStorage.TimeEx: return(reader.GetTimeEx()); case TypeStorage.ByteArray: return(reader.GetByteArray()); case TypeStorage.Guid: return(reader.GetGuid()); case TypeStorage.String: return(reader.GetString()); //case TypeStorage.Array: // return reader.GetArray(); } return(null); }
public static void WriteTo(this ICdlValueReader reader, ICdlValueWriter writer) { switch (reader.GetFieldType()) { case TypeStorage.Null: writer.SetNull(); break; case TypeStorage.Boolean: writer.SetBoolean(reader.GetBoolean()); break; case TypeStorage.Byte: writer.SetByte(reader.GetByte()); break; case TypeStorage.Int16: writer.SetInt16(reader.GetInt16()); break; case TypeStorage.Int32: writer.SetInt32(reader.GetInt32()); break; case TypeStorage.Int64: writer.SetInt64(reader.GetInt64()); break; case TypeStorage.SByte: writer.SetSByte(reader.GetSByte()); break; case TypeStorage.UInt16: writer.SetUInt16(reader.GetUInt16()); break; case TypeStorage.UInt32: writer.SetUInt32(reader.GetUInt32()); break; case TypeStorage.UInt64: writer.SetUInt64(reader.GetUInt64()); break; case TypeStorage.Float: writer.SetFloat(reader.GetFloat()); break; case TypeStorage.Double: writer.SetDouble(reader.GetDouble()); break; case TypeStorage.Decimal: writer.SetDecimal(reader.GetDecimal()); break; case TypeStorage.DateTime: writer.SetDateTime(reader.GetDateTime()); break; case TypeStorage.DateTimeEx: writer.SetDateTimeEx(reader.GetDateTimeEx()); break; case TypeStorage.DateEx: writer.SetDateEx(reader.GetDateEx()); break; case TypeStorage.TimeEx: writer.SetTimeEx(reader.GetTimeEx()); break; case TypeStorage.ByteArray: writer.SetByteArray(reader.GetByteArray()); break; case TypeStorage.Guid: writer.SetGuid(reader.GetGuid()); break; case TypeStorage.String: writer.SetString(reader.GetString()); break; } }
public string GetSqlLiteral(ICdlValueReader reader, DbTypeBase type) { //m_literalFormatter.TargetType = type; m_literalFormatter.ReadFrom(reader); return m_literalFormatter.GetText(); }
public static bool GetValueAsXml(ICdlValueReader rec, ref string xtype, ref string xdata) { var type = rec.GetFieldType(); if (type == TypeStorage.Null) { return(false); } switch (type) { case TypeStorage.Boolean: xtype = "bool"; xdata = rec.GetBoolean() ? "1" : "0"; break; case TypeStorage.Byte: xtype = "byte"; xdata = rec.GetByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int16: xtype = "i16"; xdata = rec.GetInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int32: xtype = "i32"; xdata = rec.GetInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int64: xtype = "i64"; xdata = rec.GetInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.SByte: xtype = "sbyte"; xdata = rec.GetSByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt16: xtype = "u16"; xdata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt32: xtype = "u32"; xdata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt64: xtype = "u64"; xdata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.DateTime: xtype = "datetime"; xdata = rec.GetDateTime().ToString("s", CultureInfo.InvariantCulture); break; case TypeStorage.DateTimeEx: xtype = "dtex"; xdata = rec.GetDateTimeEx().ToStringNormalized(); break; case TypeStorage.DateEx: xtype = "date"; xdata = rec.GetDateEx().ToStringNormalized(); break; case TypeStorage.TimeEx: xtype = "time"; xdata = rec.GetTimeEx().ToStringNormalized(); break; case TypeStorage.Decimal: xtype = "decimal"; xdata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Float: xtype = "float"; xdata = rec.GetFloat().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Double: xtype = "double"; xdata = rec.GetDouble().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.String: xtype = "str"; xdata = rec.GetString(); break; case TypeStorage.Guid: xtype = "guid"; xdata = rec.GetGuid().ToString(); break; case TypeStorage.ByteArray: { xtype = "blob"; byte[] data = rec.GetByteArray(); xdata = Convert.ToBase64String(data); } break; //case TypeStorage.Array: // { // xtype = "array"; // xdata = CdlArray.ToString(rec.GetArray()); // } // break; } return(true); }
public void SetValue(int colindex, ICdlValueReader reader) { var holder = new CdlValueHolder(); m_table.CdlConvertor.ConvertValue(reader, GetDefaultStorage(colindex), holder); m_fields[colindex].Value = holder.GetValue(); m_fields[colindex].Changed = true; if (RowState == CdlRowState.Unchanged) RowState = CdlRowState.Modified; }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader, DbTypeBase dsttype) { if (props.BinaryStrings) { switch (reader.GetFieldType()) { case TypeStorage.String: if (props.BinaryStrings) { return(dda.GetSqlLiteral(props.RealBinaryEncoding.GetBytes(reader.GetString()), dsttype)); } break; } } return(dda.GetSqlLiteral(reader, dsttype)); }