Ejemplo n.º 1
0
        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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static bool IsComparable(DbTypeBase type)
 {
     if (type is DbTypeXml || type is DbTypeBlob)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
        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) };
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        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);
                }
            }
        }
Ejemplo n.º 9
0
 protected override void LoadFromXml(XmlElement xml)
 {
     base.LoadFromXml(xml);
     Dims        = new ArrayDimensions(xml.GetAttribute("dims"));
     ElementType = DbTypeBase.Load(xml.FindElement("Element"));
 }
Ejemplo n.º 10
0
 public static bool IsComparable(DbTypeBase type)
 {
     if (type is DbTypeXml || type is DbTypeBlob) return false;
     return true;
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
 public static DmlfConditionBase ParseFilterExpression(DbTypeBase type, DmlfExpression columnValue, string expression, Action<DbShellFilterAntlrParser> initParser = null)
 {
     return ParseFilterExpression(GetExpressionType(type), columnValue, expression, initParser);
 }
Ejemplo n.º 14
0
 public ValueTypeHolder(object value, DbTypeBase type)
 {
     Value = value;
     DbType = type;
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
        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)
                }
            }
            ;
        }
Ejemplo n.º 18
0
 protected virtual void ConvertNotNullValue(ICdlValueReader reader, DbTypeBase type, CdlValueHolder valueHolder, ICdlValueConvertor converter)
 {
     converter.ConvertValue(reader, type.DefaultStorage, valueHolder);
 }
Ejemplo n.º 19
0
 public string GetSqlLiteral(ICdlValueReader reader, DbTypeBase type)
 {
     //m_literalFormatter.TargetType = type;
     m_literalFormatter.ReadFrom(reader);
     return m_literalFormatter.GetText();
 }
Ejemplo n.º 20
0
 public string GetSqlLiteral(object value, DbTypeBase type)
 {
     m_holder.ReadFrom(value);
     return GetSqlLiteral(m_holder, type);
 }
Ejemplo n.º 21
0
        //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);
        }