protected override void ApplyTypeRestrictions(CdlValueHolder holder, DbTypeBase type) { base.ApplyTypeRestrictions(holder, type); var dtt = type as DbTypeDatetime; if (dtt != null) { if (!dtt.ExtendedPrecision) { var htype = holder.GetFieldType(); if (htype.IsDateRelated()) { var dt = holder.GetDateTimeValue(); dt.Nanosecond = dt.Nanosecond/1000000*1000000; switch (htype) { case TypeStorage.DateEx: holder.SetDateEx(dt.DatePart); break; case TypeStorage.TimeEx: holder.SetTimeEx(dt.TimePart); break; case TypeStorage.DateTimeEx: holder.SetDateTimeEx(dt); break; case TypeStorage.DateTime: holder.SetDateTime(dt.AsDateTime); break; } } } } }
public static bool IsComparable(DbTypeBase type) { if (type is DbTypeXml || type is DbTypeBlob) { return(false); } return(true); }
public static DbTypeBase Load(XmlElement xml) { DbTypeCode code = (DbTypeCode)Enum.Parse(typeof(DbTypeCode), xml.GetAttribute("datatype"), true); DbTypeBase res = DbTypeBase.CreateType(code); res.LoadFromXml(xml); return(res); }
protected override void ConvertNotNullValue(Common.CommonDataLayer.ICdlValueReader reader, DbTypeBase type, Common.CommonDataLayer.CdlValueHolder valueHolder, Common.CommonDataLayer.ICdlValueConvertor converter) { if (type is DbTypeDatetime) { converter.ConvertValue(reader, TypeStorage.DateTime, valueHolder); } else { base.ConvertNotNullValue(reader, type, valueHolder, converter); } }
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 DbTypeParser(string dataType) { if (dataType != null) { _tokens = dataType.Replace(",", " , ").Replace("(", " ( ").Replace(")", " ) ").Split(' ') .Select(x => x.Trim().ToLower()).ToArray(); } if (StartsWith("varchar", "(", null, ")")) CommonType = new DbTypeString { IsUnicode = false, Length = IntValue(0, -1) }; if (StartsWith("nvarchar", "(", null, ")")) CommonType = new DbTypeString { IsUnicode = true, Length = IntValue(0, -1) }; if (StartsWith("char", "(", null, ")")) CommonType = new DbTypeString { IsVarLength=false, IsUnicode = false, Length = IntValue(0, -1) }; if (StartsWith("nchar", "(", null, ")")) CommonType = new DbTypeString { IsVarLength=false, IsUnicode = false, Length = IntValue(0, -1) }; if (StartsWith("varbinary", "(", null, ")")) CommonType = new DbTypeString { IsBinary = true, Length = IntValue(0, -1) }; if (StartsWith("binary", "(", null, ")")) CommonType = new DbTypeString { IsVarLength = false, IsBinary = true, Length = IntValue(0, -1) }; if (StartsWith("float")) CommonType = new DbTypeFloat(); if (StartsWith("real")) CommonType = new DbTypeFloat(); if (StartsWith("money")) CommonType = new DbTypeFloat { IsMoney = true }; if (StartsWith("smallmoney")) CommonType = new DbTypeFloat { IsMoney = true }; if (StartsWith("bit")) CommonType = new DbTypeLogical(); if (StartsWith("image")) CommonType = new DbTypeBlob(); if (StartsWith("tinyint")) CommonType = new DbTypeInt { Bytes = 1 }; if (StartsWith("smallint")) CommonType = new DbTypeInt { Bytes = 2 }; if (StartsWith("int")) CommonType = new DbTypeInt { Bytes = 4 }; if (StartsWith("bigint")) CommonType = new DbTypeInt { Bytes = 8 }; if (StartsWith("datetime")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime }; if (StartsWith("datetime2")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime, ExtendedPrecision = true }; if (StartsWith("datetimeoffset")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime, HasTimeZone = true }; if (StartsWith("date")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Date}; if (StartsWith("time")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Time}; if (StartsWith("smalldatetime")) CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime }; if (StartsWith("text")) CommonType = new DbTypeText(); if (StartsWith("ntext")) CommonType = new DbTypeText { IsUnicode = true }; if (StartsWith("xml")) CommonType = new DbTypeXml(); if (StartsWith("sql_variant")) CommonType = new DbTypeText(); if (StartsWith("decimal")) CommonType = new DbTypeNumeric(); if (StartsWith("numeric")) CommonType = new DbTypeNumeric(); if (StartsWith("decimal", "(", null, ",", null, ")")) CommonType = new DbTypeNumeric { Precision = IntValue(0, 10), Scale = IntValue(1, 0) }; if (StartsWith("numeric", "(", null, ",", null, ")")) CommonType = new DbTypeNumeric { Precision = IntValue(0, 10), Scale = IntValue(1, 0) }; }
public virtual void GetNativeDataType(DbTypeBase commonType, ColumnInfo columnInfo) { switch (commonType.Code) { case DbTypeCode.Blob: columnInfo.DataType = "blob"; return; case DbTypeCode.Datetime: columnInfo.DataType = "datetime"; return; case DbTypeCode.String: var str = (DbTypeString) commonType; columnInfo.DataType = str.GetStandardSqlName(); columnInfo.Length = str.Length; return; case DbTypeCode.Guid: columnInfo.DataType = "varchar"; columnInfo.Length = 50; return; case DbTypeCode.Float: columnInfo.DataType = "float"; return; case DbTypeCode.Numeric: columnInfo.DataType = "numeric"; columnInfo.Precision = commonType.GetLength(); columnInfo.Scale = commonType.GetScale(); return; case DbTypeCode.Text: case DbTypeCode.Xml: columnInfo.DataType = "nvarchar"; columnInfo.Length = -1; return; case DbTypeCode.Logical: columnInfo.DataType = "int"; return; } columnInfo.DataType = "varchar"; columnInfo.Length = 50; }
protected virtual void ApplyTypeRestrictions(CdlValueHolder holder, DbTypeBase type) { var stype = type as DbTypeString; var htype = holder.GetFieldType(); if (stype != null && htype == TypeStorage.String) { string sval = holder.GetString(); if (stype.Length > 0 && sval.Length > stype.Length) { sval = sval.Substring(0, stype.Length); holder.SetString(sval); } } if (htype.IsDateRelated() && !m_allowZeroInDate) { var dt = holder.GetDateTimeValue(); if (dt.MakeValidDate()) { m_holder.SetDateTimeEx(dt); } } }
protected override void LoadFromXml(XmlElement xml) { base.LoadFromXml(xml); Dims = new ArrayDimensions(xml.GetAttribute("dims")); ElementType = DbTypeBase.Load(xml.FindElement("Element")); }
public static bool IsComparable(DbTypeBase type) { if (type is DbTypeXml || type is DbTypeBlob) return false; return true; }
public static string GetSqlLiteralAndRead(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, object val, DbTypeBase dsttype) { if (state == null) state = new SqlFormatterState(); state._Holder.ReadFrom(val); return GetSqlLiteral(props, dda, state, state._Holder, dsttype); }
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 DmlfConditionBase ParseFilterExpression(DbTypeBase type, DmlfExpression columnValue, string expression, Action<DbShellFilterAntlrParser> initParser = null) { return ParseFilterExpression(GetExpressionType(type), columnValue, expression, initParser); }
public ValueTypeHolder(object value, DbTypeBase type) { Value = value; DbType = type; }
public ColumnInfo AddColumn(string columnName, string dataType, DbTypeBase commonType) { var newColumn = new ColumnInfo(this) { Name = columnName, DataType = dataType, CommonType = commonType, }; Columns.Add(newColumn); return newColumn; }
public static ExpressionType GetExpressionType(DbTypeBase type) { if (type != null) { switch (type.Code) { case DbTypeCode.Int: case DbTypeCode.Numeric: case DbTypeCode.Float: return ExpressionType.Number; case DbTypeCode.Text: case DbTypeCode.String: case DbTypeCode.Guid: return ExpressionType.String; case DbTypeCode.Datetime: return ExpressionType.DateTime; case DbTypeCode.Logical: return ExpressionType.Logical; } } return ExpressionType.None; }
public DbTypeParser(string dataType) { if (dataType != null) { _tokens = dataType.Replace(",", " , ").Replace("(", " ( ").Replace(")", " ) ").Split(' ') .Select(x => x.Trim().ToLower()).ToArray(); } if (StartsWith("varchar", "(", null, ")")) { CommonType = new DbTypeString { IsUnicode = false, Length = IntValue(0, -1) } } ; if (StartsWith("nvarchar", "(", null, ")")) { CommonType = new DbTypeString { IsUnicode = true, Length = IntValue(0, -1) } } ; if (StartsWith("char", "(", null, ")")) { CommonType = new DbTypeString { IsVarLength = false, IsUnicode = false, Length = IntValue(0, -1) } } ; if (StartsWith("nchar", "(", null, ")")) { CommonType = new DbTypeString { IsVarLength = false, IsUnicode = false, Length = IntValue(0, -1) } } ; if (StartsWith("varbinary", "(", null, ")")) { CommonType = new DbTypeString { IsBinary = true, Length = IntValue(0, -1) } } ; if (StartsWith("binary", "(", null, ")")) { CommonType = new DbTypeString { IsVarLength = false, IsBinary = true, Length = IntValue(0, -1) } } ; if (StartsWith("float")) { CommonType = new DbTypeFloat(); } if (StartsWith("real")) { CommonType = new DbTypeFloat(); } if (StartsWith("money")) { CommonType = new DbTypeFloat { IsMoney = true } } ; if (StartsWith("smallmoney")) { CommonType = new DbTypeFloat { IsMoney = true } } ; if (StartsWith("bit")) { CommonType = new DbTypeLogical(); } if (StartsWith("image")) { CommonType = new DbTypeBlob(); } if (StartsWith("tinyint")) { CommonType = new DbTypeInt { Bytes = 1 } } ; if (StartsWith("smallint")) { CommonType = new DbTypeInt { Bytes = 2 } } ; if (StartsWith("int")) { CommonType = new DbTypeInt { Bytes = 4 } } ; if (StartsWith("bigint")) { CommonType = new DbTypeInt { Bytes = 8 } } ; if (StartsWith("datetime")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime } } ; if (StartsWith("datetime2")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime, ExtendedPrecision = true } } ; if (StartsWith("datetimeoffset")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime, HasTimeZone = true } } ; if (StartsWith("date")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Date } } ; if (StartsWith("time")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Time } } ; if (StartsWith("smalldatetime")) { CommonType = new DbTypeDatetime { SubType = DbDatetimeSubType.Datetime } } ; if (StartsWith("text")) { CommonType = new DbTypeText(); } if (StartsWith("ntext")) { CommonType = new DbTypeText { IsUnicode = true } } ; if (StartsWith("xml")) { CommonType = new DbTypeXml(); } if (StartsWith("sql_variant")) { CommonType = new DbTypeText(); } if (StartsWith("decimal")) { CommonType = new DbTypeNumeric(); } if (StartsWith("numeric")) { CommonType = new DbTypeNumeric(); } if (StartsWith("decimal", "(", null, ",", null, ")")) { CommonType = new DbTypeNumeric { Precision = IntValue(0, 10), Scale = IntValue(1, 0) } } ; if (StartsWith("numeric", "(", null, ",", null, ")")) { CommonType = new DbTypeNumeric { Precision = IntValue(0, 10), Scale = IntValue(1, 0) } } ; }
protected virtual void ConvertNotNullValue(ICdlValueReader reader, DbTypeBase type, CdlValueHolder valueHolder, ICdlValueConvertor converter) { converter.ConvertValue(reader, type.DefaultStorage, valueHolder); }
public string GetSqlLiteral(ICdlValueReader reader, DbTypeBase type) { //m_literalFormatter.TargetType = type; m_literalFormatter.ReadFrom(reader); return m_literalFormatter.GetText(); }
public string GetSqlLiteral(object value, DbTypeBase type) { m_holder.ReadFrom(value); return GetSqlLiteral(m_holder, type); }
//public static Type TypeFromName(string name) //{ // switch (name) // { // case "int": return typeof(Int32); // case "numeric": return typeof(Decimal); // case "varchar": return typeof(String); // case "nvarchar": return typeof(String); // case "image": return typeof(byte[]); // } // return Type.GetType(name); //} public static DbType GetProviderType(DbTypeBase type) { return GetProviderType(type.DotNetType); }