Example #1
0
        /// <summary>
        /// 使用FileStream类进行文件的读取,并转换成char数组
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns>char[]</returns>
        public static char[] Read_Char(string filePath)
        {
            byte[] byData   = new byte[100];
            char[] charData = new char[1000];
            try
            {
                if (!IsNull.Null(filePath))
                {
                    return(charData);
                }
                FileStream file = new FileStream(filePath, FileMode.Open);
                file.Seek(0, SeekOrigin.Begin);
                file.Read(byData, 0, 100);
                Decoder d = Encoding.Default.GetDecoder();
                d.GetChars(byData, 0, byData.Length, charData, 0);
                file.Close();
                return(charData);
            }
            catch (Exception e)
            {
                return(charData);

                throw e;
            }
        }
Example #2
0
        public override int GetHashCode()
        {
            int num;

            if (PropertyAsObject == null)
            {
                num = 0;
            }
            else if (PropertyType == EdmType.Binary)
            {
                num = 0;
                byte[] array = (byte[])PropertyAsObject;
                if (array.Length != 0)
                {
                    for (int i = 0; i < Math.Min(array.Length - 4, 1024); i += 4)
                    {
                        num ^= BitConverter.ToInt32(array, i);
                    }
                }
            }
            else
            {
                num = PropertyAsObject.GetHashCode();
            }
            return(num ^ PropertyType.GetHashCode() ^ IsNull.GetHashCode());
        }
Example #3
0
        /// <summary>
        /// 写入文本文件并保存
        /// </summary>
        /// <param name="filePath">保存路径(完整路径,如:e:\123\)</param>
        /// <param name="content">文件内容</param>
        ///<param name="fileName">文件名称</param>
        /// <returns></returns>
        public static int Write(string filePath, string content, string fileName)
        {
            try
            {
                if (IsNull.Null(filePath) && IsNull.Null(content) && IsNull.Null(fileName))
                {
                    if (!Directory.Exists(filePath))
                    {
                        Directory.CreateDirectory(filePath);
                    }
                    FileStream fs = new FileStream(filePath + fileName + ".log", FileMode.Create);

                    //获得字节数组
                    byte[] data = System.Text.Encoding.Default.GetBytes(content);
                    //开始写入
                    fs.Write(data, 0, data.Length);
                    //清空缓冲区、关闭流
                    fs.Flush();
                    fs.Close();
                }
                return(0);
            }
            catch (Exception e)
            {
                return(0);

                throw e;
            }
        }
Example #4
0
        /// <summary>
        /// Deserializes the specified configuration in an <see cref="IsNull"/> object
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        public override SqlTag Deserialize(IConfiguration configuration)
        {
            IsNull isNull = new IsNull(accessorFactory);

            isNull.Prepend  = ConfigurationUtils.GetStringAttribute(configuration.Attributes, ConfigConstants.ATTRIBUTE_PREPEND);
            isNull.Property = ConfigurationUtils.GetStringAttribute(configuration.Attributes, ConfigConstants.ATTRIBUTE_PROPERTY);

            return(isNull);
        }
Example #5
0
        public SqlTag Deserialize(XmlNode node)
        {
            IsNull @null = new IsNull(this._configScope.DataExchangeFactory.AccessorFactory);
            NameValueCollection attributes = NodeUtils.ParseAttributes(node, this._configScope.Properties);

            @null.Prepend  = NodeUtils.GetStringAttribute(attributes, "prepend");
            @null.Property = NodeUtils.GetStringAttribute(attributes, "property");
            return(@null);
        }
Example #6
0
        public void IsNull_HandlesType_ReturnsIsNullType()
        {
            var decisionType = enDecisionType.IsNull;
            //------------Setup for test--------------------------
            var isNull = new IsNull();

            //------------Execute Test---------------------------
            //------------Assert Results-------------------------
            Assert.AreEqual(decisionType, isNull.HandlesType());
        }
Example #7
0
        public void IsNullRuleIsValid()
        {
            object target = null;
            IsNull rule   = new IsNull("IsNotNull", "The target is null. Cannot be null.", target);
            Result result = rule.Execute();

            Assert.IsTrue(result.IsValid);
            Assert.IsNotNullOrEmpty(result.Message);
            Assert.IsNotNull(result.RulePolicy);
            Assert.AreEqual(result.RulePolicy.Severity, Severity.Exception);
        }
Example #8
0
        public override int GetHashCode()
        {
            int result = Name != null?Name.GetHashCode() : 0;

            result = 31 * result + (Type != null ? Type.GetHashCode() : 0);
            result = 31 * result + (IsNull != null ? IsNull.GetHashCode() : 0);
            result = 31 * result + (DefaultValue != null ? DefaultValue.GetHashCode() : 0);
            result = 31 * result + (Comment != null ? Comment.GetHashCode() : 0);
            result = 31 * result + (Extra != null ? Extra.GetHashCode() : 0);

            return(base.GetHashCode());
        }
Example #9
0
        public void IsNull_Invoke_IsNull_ReturnsTrue()
        {
            //------------Setup for test--------------------------
            var notStartsWith = new IsNull();

            string[] cols = new string[2];
            cols[0] = null;
            //------------Execute Test---------------------------
            bool result = notStartsWith.Invoke(cols);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
Example #10
0
            protected override ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
            {
                if (!doClone(this))
                {
                    return(this);
                }

                if (!objectTree.TryGetValue(this, out var clone))
                {
                    objectTree.Add(this, clone = new IsNull((ISqlExpression)Expr1.Clone(objectTree, doClone), IsNot));
                }

                return(clone);
            }
Example #11
0
        public static string IsNullDescription(this IsNull isNull)
        {
            switch (isNull)
            {
            case IsNull.Null:
                return("");

            case IsNull.NotNull:
                return("是");

            default:
                return("");
            }
        }
Example #12
0
        public void GivenSomeString_IsNull_Invoke_ReturnsFalse()
        {
            //------------Setup for test--------------------------
            var isNull = new IsNull();

            string[] cols = new string[2];
            cols[0] = "Eight";
            //------------Execute Test---------------------------
            bool result = isNull.Invoke(cols);

            //------------Assert Results-------------------------
            Assert.IsFalse(result);
            //------------Execute Test---------------------------
            result = isNull.Invoke(null);
            //------------Assert Results-------------------------
            Assert.IsFalse(result);
        }
        private static ConditionResult VerifyCondition(List <object> objects, IsNull valueNullCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = valueNullCondition
            };
            List <string> info = new List <string>();

            var requiredState = valueNullCondition.NullCondition;

            foreach (var obj in objects)
            {
                bool   passed = false;
                object value  = obj.ValueFromSource(valueNullCondition.PropertyName);

                if (requiredState == ValueNullConditions.MustBeNull)
                {
                    passed = value == null;
                }
                else if (requiredState == ValueNullConditions.MustBeNotNull)
                {
                    passed = value != null;
                }

                if (passed)
                {
                    result.PassedObjects.Add(obj);
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    info.Add($"{(string.IsNullOrWhiteSpace(valueNullCondition.Clause) ? "" : valueNullCondition.Clause + " failed: ")}" +
                             $"{valueNullCondition.PropertyName} was {value ?? "empty"}, which does not respect '{valueNullCondition.ToString()}'.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = info;
            return(result);
        }
Example #14
0
        //入力値をデータベースに反映
        public void SetUnitPrice(List <BeforeSubmittingQuotation> quotations)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var deleteZero = quotations
                                 .Where(s => s.UnitPrice > 0);

                List <Quotation> results = new List <Quotation>();

                foreach (var item in deleteZero)
                {
                    var quotation = db.Quotations
                                    .Single(q => q.Id == item.Id);
                    quotation.Quantity  = item.Quantity;
                    quotation.UnitPrice = item.UnitPrice;
                    quotation.Arrival   = IsNull.ToString(item.Arrival);
                    quotation.Detail    = IsNull.ToString(item.Detail);

                    db.SaveChanges();
                }
            }
        }
Example #15
0
        /// <summary>
        /// 使用StreamReader类进行文件的读取,返回String
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns>string</returns>
        public static string Read_String(string filePath)
        {
            try
            {
                if (!IsNull.Null(filePath))
                {
                    return(null);
                }
                StreamReader  sr = new StreamReader(filePath, Encoding.Default);
                StringBuilder sb = new StringBuilder();
                foreach (var item in sr.ReadLine())
                {
                    sb.Append(item.ToString());
                }
                return(sb.ToString());
            }
            catch (Exception e)
            {
                return(null);

                throw e;
            }
        }
        public static void CreateFilter(object sender, object selectedItem)
        {
            if (selectedItem is FilterCollectionViewModel filterCollectionViewModel)
            {
                CreateFilter(sender, filterCollectionViewModel.Parent);
                return;
            }

            var button = (Button)sender;

            var type = (string)button.CommandParameter;

            FilterBase entity;

            switch (type)
            {
            case nameof(ActiveOn):
                entity = ActiveOn.New("0001-01-01");
                break;

            case nameof(ActiveWithin):
                entity = ActiveWithin.New("0001-01-01,0001-01-01");
                break;

            case nameof(OfType):
                entity = OfType.New("TypeName");
                break;

            case nameof(NotOfType):
                entity = NotOfType.New("TypeName");
                break;

            case nameof(Contain):
                entity = Contain.New("Property", "Value");
                break;

            case nameof(NotContain):
                entity = NotContain.New("Property", "Value");
                break;

            case nameof(EqualTo):
                entity = EqualTo.New("Property", "Value");
                break;

            case nameof(NotEqualTo):
                entity = NotEqualTo.New("Property", "Value");
                break;

            case nameof(GreaterThan):
                entity = GreaterThan.New("Property", "Value");
                break;

            case nameof(LessThan):
                entity = LessThan.New("Property", "Value");
                break;

            case nameof(GreaterThanEqualTo):
                entity = GreaterThanEqualTo.New("Property", "Value");
                break;

            case nameof(LessThanEqualTo):
                entity = LessThanEqualTo.New("Property", "Value");
                break;

            case nameof(Between):
                entity = Between.New("Property", "0001-01-01", "0001-01-01");
                break;

            case nameof(WithinArray):
                entity = WithinArray.New("Property", "ValueA,ValueB,ValueC");
                break;

            case nameof(NotWithinArray):
                entity = NotWithinArray.New("Property", "ValueA,ValueB,ValueC");
                break;

            case nameof(IsNull):
                entity = IsNull.New("Property");
                break;

            case nameof(IsNotNull):
                entity = IsNotNull.New("Property");
                break;

            case nameof(IsNullOrGreaterThan):
                entity = IsNullOrGreaterThan.New("Property", "Value");
                break;

            case nameof(IsNullOrGreaterThanEqualTo):
                entity = IsNullOrGreaterThanEqualTo.New("Property", "Value");
                break;

            case nameof(IsNullOrLessThan):
                entity = IsNullOrLessThan.New("Property", "Value");
                break;

            case nameof(IsNullOrLessThanEqualTo):
                entity = IsNullOrLessThanEqualTo.New("Property", "Value");
                break;

            case nameof(StartsWith):
                entity = StartsWith.New("Property", "Value");
                break;

            case nameof(EndsWith):
                entity = EndsWith.New("Property", "Value");
                break;

            case nameof(TakeFirst):
                entity = TakeFirst.New(1);
                break;

            case nameof(OfDerivedType):
                entity = OfDerivedType.New("TypeName");
                break;

            case nameof(NotOfDerivedType):
                entity = NotOfDerivedType.New("TypeName");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            FilterViewModel           viewModel;
            FilterCollectionViewModel viewModelCollection;

            if (selectedItem is GroupViewModel entityGroupViewModel)
            {
                entityGroupViewModel.IsExpanded = true;

                entityGroupViewModel.Element.Filters.Add(entity);
                viewModelCollection = entityGroupViewModel.Children.OfType <FilterCollectionViewModel>().First();

                viewModel = new FilterViewModel(entity, viewModelCollection);
                viewModelCollection.Children.Add(viewModel);
            }
            else if (selectedItem is OutputViewModel outputViewModel)
            {
                if (!(outputViewModel.Element is AggregateOutputBase elementAsAggregate))
                {
                    return;
                }

                outputViewModel.IsExpanded = true;

                elementAsAggregate.Filters.Add(entity);
                viewModelCollection = outputViewModel.Children.OfType <FilterCollectionViewModel>().First();

                viewModel = new FilterViewModel(entity, viewModelCollection);
                viewModelCollection.Children.Add(viewModel);
            }
            else
            {
                return;
            }

            viewModelCollection.IsExpanded = true;
            viewModel.IsSelected           = true;
            viewModel.IsExpanded           = true;
        }
Example #17
0
        public ITag Build(XmlNode xmlNode)
        {
            ITag tag          = null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId       = xmlNode.Attributes?["RefId"]?.Value;
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                //includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    Test         = xmlNode.Attributes?["Test"]?.Value.Trim(),
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Bind":
            {
                tag = new BindTag
                {
                    Name  = xmlNode.Attributes["Name"]?.Value,
                    Value = xmlNode.Attributes["Value"]?.Value,
                };
                break;
            }

            case "Trim":
            {
                tag = new TrimTag
                {
                    Prefix          = xmlNode.Attributes["Prefix"]?.Value,
                    PrefixOverrides = xmlNode.Attributes["PrefixOverrides"]?.Value,
                    Suffix          = xmlNode.Attributes["Suffix"]?.Value,
                    ChildTags       = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "If":
            {
                var test = xmlNode.Attributes["Test"]?.Value;
                tag = new IfTag
                {
                    Test = test
                };
            }
            break;

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            #endregion
            return(tag);
        }
Example #18
0
        private ITag LoadTag(XmlNode xmlNode, Statement statement)
        {
            ITag tag          = null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var innerText = xmlNode.InnerText;
                var bodyText  = innerText;
                //bodyText += innerText.Trim().Replace("\r", " ").Replace("\n", " ");
                //bodyText += " ";
                return(new SqlText
                    {
                        Statement = statement,
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId = xmlNode.Attributes?["RefId"]?.Value;
                if (refId.IndexOf('.') < 0)
                {
                    refId = $"{statement.SmartSqlMap.Scope}.{refId}";
                }
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = xmlNode.Attributes?["Prepend"]?.Value
                };
                statement.IncludeDependencies.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = xmlNode.Attributes?["Prepend"]?.Value,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { return(null); }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            tag.Statement = statement;
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, statement);
                if (childTag != null && tag != null)
                {
                    childTag.Parent = tag;
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }
Example #19
0
 private void Expand(IsNull isNull)
 {
     ExpandExpression(isNull.Expression);
     builder.Append(" is null");
 }
Example #20
0
        private void Criteria_Activated(object sender, EventArgs e)
        {
            DisableValueFields();
            if (BasicOp.Checked)
            {
                Value.Enabled = true;
                if (Visible)
                {
                    Value.Focus();
                }
            }

            else if (InList.Checked)
            {
                ValueList.Enabled  = true;
                ImportList.Enabled = true;
                EditList.Enabled   = true;
                if (Visible)
                {
                    ValueList.Focus();
                }
            }

            else if (Between.Checked)
            {
                Limit1.Enabled = true;
                Limit2.Enabled = true;
                if (Visible)
                {
                    Limit1.Focus();
                }
            }

            else if (Like.Checked)
            {
                Substring.Enabled = true;
                if (Visible)
                {
                    Substring.Focus();
                }
            }

            else if (Within.Checked)
            {
                WithinValue.Enabled = true;
                WithinUnits.Enabled = true;
                if (Visible)
                {
                    WithinValue.Focus();
                }
            }

            else if (All.Checked)
            {
                All.Focus();
            }

            else if (IsNotNull.Checked)
            {
                IsNotNull.Focus();
            }

            else if (IsNull.Checked)
            {
                IsNull.Focus();
            }

            else if (None.Checked)
            {
                None.Focus();
            }
        }
Example #21
0
 protected bool Equals(IsNull other)
 {
     return(base.Equals(other) && Equals(Expression, other.Expression) && Negate == other.Negate);
 }
Example #22
0
        public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            bool isIn         = xmlNode.Attributes?["In"] != null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId       = xmlNode.Attributes?["RefId"]?.Value;
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, includes);
                if (childTag != null && tag != null)
                {
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }
Example #23
0
        public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            bool isIn         = !string.IsNullOrEmpty(xmlNode.GetValueInXmlAttributes("In"));
            var  prepend      = xmlNode.GetValueInXmlAttributes("Prepend");
            var  property     = xmlNode.GetValueInXmlAttributes("Property");
            var  compareValue = xmlNode.GetValueInXmlAttributes("CompareValue");

            #region Init Tag
            string lowerXmlNodeName = xmlNode.Name.ToLower();
            switch (lowerXmlNodeName)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            //case "OrderBy":
            case "orderby":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                tag = new OrderBy
                {
                    ChildTags = new List <ITag>(),

                    BodyText = bodyText
                };
                break;
            }

            //case "Include":
            case "include":
            {
                var refId       = xmlNode.GetValueInXmlAttributes("RefId");
                var include_tag = new Include
                {
                    RefId = refId
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            //case "If":
            case "if":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                tag = new IfTag
                {
                    Test      = Test,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEmpty":
            case "isempty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEqual":
            case "isequal":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterEqual":
            case "isgreaterequal":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterThan":
            case "isgreaterthan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessEqual":
            case "islessequal":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessThan":
            case "islessthan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotEmpty":
            case "isnotempty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNotEqual":
            case "isnotequal":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotNull":
            case "isnotnull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNull":
            case "isnull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsTrue":
            case "istrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsFalse":
            case "isfalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsProperty":
            case "isproperty":
            {
                tag = new IsProperty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Switch":
            case "switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Case":
            case "case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "Default":
            case "default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Choose":
            case "choose":
            {
                tag = new ChooseTag
                {
                    //Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "when":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseWhenTag
                {
                    Test = Test,
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "otherwise":
            {
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseOtherwiseTag
                {
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "trim":
            {
                var Prefix          = xmlNode.GetValueInXmlAttributes("Prefix", "", false);
                var Suffix          = xmlNode.GetValueInXmlAttributes("Suffix", "", false);
                var PrefixOverrides = xmlNode.GetValueInXmlAttributes("PrefixOverrides");
                var SuffixOverrides = xmlNode.GetValueInXmlAttributes("SuffixOverrides");
                tag = new TrimTag
                {
                    Prefix          = Prefix,
                    Suffix          = Suffix,
                    PrefixOverrides = PrefixOverrides,
                    SuffixOverrides = SuffixOverrides,
                    ChildTags       = new List <ITag>()
                };
                break;
            }

            case "set":
            {
                tag = new SetTag()
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "where":
            {
                tag = new WhereTag
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Where":
            //case "where":
            //    {
            //        tag = new Where
            //        {
            //            ChildTags = new List<ITag>()
            //        };
            //        break;
            //    }
            //case "Dynamic":
            case "dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Variable":
            case "variable":
            {
                var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new Variable
                {
                    BodyText  = bodyText,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Bind":
            case "bind":
            {
                var Name  = xmlNode.GetValueInXmlAttributes("Name");
                var Value = xmlNode.GetValueInXmlAttributes("Value");
                //var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new BindTag
                {
                    Name      = Name,
                    Value     = Value,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Foreach":
            case "foreach":
            {
                var open      = xmlNode.GetValueInXmlAttributes("Open");
                var separator = xmlNode.GetValueInXmlAttributes("Separator");
                var close     = xmlNode.GetValueInXmlAttributes("Close");
                var item      = xmlNode.GetValueInXmlAttributes("Item");
                var index     = xmlNode.GetValueInXmlAttributes("Index");
                tag = new Foreach
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Item      = item,
                    Index     = index,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Env":
            case "env":
            {
                var dbProvider = xmlNode.GetValueInXmlAttributes("DbProvider");
                var DbType     = xmlNode.GetValueInXmlAttributes("DbType");
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    DbType     = DbType,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new Exception(string.Format("Statement.LoadTag unkonw tagName:{0}.", xmlNode.Name));
            };
            }
            #endregion
            //加载组合查询条件查询
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, includes);
                if (childTag != null && tag != null)
                {
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }
 public AssignNode(Symbol symbol, IsNull isNull, FlowNode next)
     : base(next)
 {
     this.symbol = symbol;
     this.isNull = isNull;
 }
Example #25
0
        private IQueryElement ConvertInternal(IQueryElement element, Func <IQueryElement, IQueryElement> action)
        {
            if (element == null)
            {
                return(null);
            }

            IQueryElement newElement;

            if (_visitedElements.TryGetValue(element, out newElement))
            {
                return(newElement);
            }

            switch (element.ElementType)
            {
            case EQueryElementType.SqlFunction:
            {
                var func  = (ISqlFunction)element;
                var parms = Convert(func.Parameters, action);

                if (parms != null && !ReferenceEquals(parms, func.Parameters))
                {
                    newElement = new SqlFunction(func.SystemType, func.Name, func.Precedence, parms);
                }

                break;
            }

            case EQueryElementType.SqlExpression:
            {
                var expr      = (ISqlExpression)element;
                var parameter = Convert(expr.Parameters, action);

                if (parameter != null && !ReferenceEquals(parameter, expr.Parameters))
                {
                    newElement = new SqlExpression(expr.SystemType, expr.Expr, expr.Precedence, parameter);
                }

                break;
            }

            case EQueryElementType.SqlBinaryExpression:
            {
                var bexpr = (ISqlBinaryExpression)element;
                var expr1 = (IQueryExpression)ConvertInternal(bexpr.Expr1, action);
                var expr2 = (IQueryExpression)ConvertInternal(bexpr.Expr2, action);

                if (expr1 != null && !ReferenceEquals(expr1, bexpr.Expr1) ||
                    expr2 != null && !ReferenceEquals(expr2, bexpr.Expr2))
                {
                    newElement = new SqlBinaryExpression(bexpr.SystemType, expr1 ?? bexpr.Expr1, bexpr.Operation,
                                                         expr2 ?? bexpr.Expr2, bexpr.Precedence);
                }

                break;
            }

            case EQueryElementType.SqlTable:
            {
                var table   = (ISqlTable)element;
                var fields1 = ToArray(table.Fields);
                var fields2 = Convert(fields1, action, f => new SqlField(f));
                var targs   = table.TableArguments == null
                        ? null
                        : Convert(table.TableArguments, action);

                var fe = fields2 == null || ReferenceEquals(fields1, fields2);
                var ta = ReferenceEquals(table.TableArguments, targs);

                if (!fe || !ta)
                {
                    if (fe)
                    {
                        fields2 = fields1;

                        for (var i = 0; i < fields2.Length; i++)
                        {
                            var field = fields2[i];

                            fields2[i] = new SqlField(field);

                            _visitedElements[field] = fields2[i];
                        }
                    }

                    newElement = new SqlTable(table, fields2, targs ?? table.TableArguments);
                }

                break;
            }

            case EQueryElementType.Column:
            {
                var col  = (IColumn)element;
                var expr = (IQueryExpression)ConvertInternal(col.Expression, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(col.Parent, out parent);

                if (parent != null || expr != null && !ReferenceEquals(expr, col.Expression))
                {
                    newElement = new Column(parent == null
                            ? col.Parent
                            : (ISelectQuery)parent, expr ?? col.Expression, col.Alias);
                }

                break;
            }

            case EQueryElementType.TableSource:
            {
                var table  = (ITableSource)element;
                var source = (ISqlTableSource)ConvertInternal(table.Source, action);
                var joins  = Convert(table.Joins, action);

                if (source != null && !ReferenceEquals(source, table.Source) ||
                    joins != null && !ReferenceEquals(table.Joins, joins))
                {
                    newElement = new TableSource(source ?? table.Source, table.Alias, joins ?? table.Joins);
                }

                break;
            }

            case EQueryElementType.JoinedTable:
            {
                var join  = (IJoinedTable)element;
                var table = (ITableSource)ConvertInternal(join.Table, action);
                var cond  = (ISearchCondition)ConvertInternal(join.Condition, action);

                if (table != null && !ReferenceEquals(table, join.Table) ||
                    cond != null && !ReferenceEquals(cond, join.Condition))
                {
                    newElement = new JoinedTable(join.JoinType, table ?? join.Table, join.IsWeak,
                                                 cond ?? join.Condition);
                }

                break;
            }

            case EQueryElementType.SearchCondition:
            {
                var sc    = (ISearchCondition)element;
                var conds = Convert(sc.Conditions, action);

                if (conds != null && !ReferenceEquals(sc.Conditions, conds))
                {
                    newElement = new SearchCondition(conds);
                }

                break;
            }

            case EQueryElementType.Condition:
            {
                var c = (Condition)element;
                var p = (ISqlPredicate)ConvertInternal(c.Predicate, action);

                if (p != null && !ReferenceEquals(c.Predicate, p))
                {
                    newElement = new Condition(c.IsNot, p, c.IsOr);
                }

                break;
            }

            case EQueryElementType.ExprPredicate:
            {
                var p = (IExpr)element;
                var e = (IQueryExpression)ConvertInternal(p.Expr1, action);

                if (e != null && !ReferenceEquals(p.Expr1, e))
                {
                    newElement = new Expr(e, p.Precedence);
                }

                break;
            }

            case EQueryElementType.NotExprPredicate:
            {
                var p = (INotExpr)element;
                var e = (IQueryExpression)ConvertInternal(p.Expr1, action);

                if (e != null && !ReferenceEquals(p.Expr1, e))
                {
                    newElement = new NotExpr(e, p.IsNot, p.Precedence);
                }

                break;
            }

            case EQueryElementType.ExprExprPredicate:
            {
                var p  = (IExprExpr)element;
                var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action);

                if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2))
                {
                    newElement = new ExprExpr(e1 ?? p.Expr1, p.EOperator, e2 ?? p.Expr2);
                }

                break;
            }

            case EQueryElementType.LikePredicate:
            {
                var p  = (ILike)element;
                var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action);
                var es = (IQueryExpression)ConvertInternal(p.Escape, action);

                if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2) ||
                    es != null && !ReferenceEquals(p.Escape, es))
                {
                    newElement = new Like(e1 ?? p.Expr1, p.IsNot, e2 ?? p.Expr2, es ?? p.Escape);
                }

                break;
            }

            case EQueryElementType.HierarhicalPredicate:
            {
                var p  = (IHierarhicalPredicate)element;
                var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action);

                if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2))
                {
                    newElement = new HierarhicalPredicate(e1 ?? p.Expr1, e2 ?? p.Expr2, p.Flow);
                }

                break;
            }

            case EQueryElementType.BetweenPredicate:
            {
                var p  = (IBetween)element;
                var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action);
                var e3 = (IQueryExpression)ConvertInternal(p.Expr3, action);

                if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2) ||
                    e3 != null && !ReferenceEquals(p.Expr3, e3))
                {
                    newElement = new Between(e1 ?? p.Expr1, p.IsNot, e2 ?? p.Expr2, e3 ?? p.Expr3);
                }

                break;
            }

            case EQueryElementType.IsNullPredicate:
            {
                var p = (IIsNull)element;
                var e = (IQueryExpression)ConvertInternal(p.Expr1, action);

                if (e != null && !ReferenceEquals(p.Expr1, e))
                {
                    newElement = new IsNull(e, p.IsNot);
                }

                break;
            }

            case EQueryElementType.InSubQueryPredicate:
            {
                var p = (IInSubQuery)element;
                var e = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var q = (ISelectQuery)ConvertInternal(p.SubQuery, action);

                if (e != null && !ReferenceEquals(p.Expr1, e) || q != null && !ReferenceEquals(p.SubQuery, q))
                {
                    newElement = new InSubQuery(e ?? p.Expr1, p.IsNot, q ?? p.SubQuery);
                }

                break;
            }

            case EQueryElementType.InListPredicate:
            {
                var p = (IInList)element;
                var e = (IQueryExpression)ConvertInternal(p.Expr1, action);
                var v = Convert(p.Values, action);

                if (e != null && !ReferenceEquals(p.Expr1, e) || v != null && !ReferenceEquals(p.Values, v))
                {
                    newElement = new InList(e ?? p.Expr1, p.IsNot, v ?? p.Values);
                }

                break;
            }

            case EQueryElementType.FuncLikePredicate:
            {
                var p = (IFuncLike)element;
                var f = (ISqlFunction)ConvertInternal(p.Function, action);

                if (f != null && !ReferenceEquals(p.Function, f))
                {
                    newElement = new FuncLike(f);
                }

                break;
            }

            case EQueryElementType.SetExpression:
            {
                var s = (ISetExpression)element;
                var c = (IQueryExpression)ConvertInternal(s.Column, action);
                var e = (IQueryExpression)ConvertInternal(s.Expression, action);

                if (c != null && !ReferenceEquals(s.Column, c) || e != null && !ReferenceEquals(s.Expression, e))
                {
                    newElement = new SetExpression(c ?? s.Column, e ?? s.Expression);
                }

                break;
            }

            case EQueryElementType.InsertClause:
            {
                var s = (IInsertClause)element;
                var t = s.Into != null
                        ? (ISqlTable)ConvertInternal(s.Into, action)
                        : null;
                var i = Convert(s.Items, action);

                if (t != null && !ReferenceEquals(s.Into, t) || i != null && !ReferenceEquals(s.Items, i))
                {
                    var sc = new InsertClause
                    {
                        Into = t ?? s.Into
                    };

                    (i ?? s.Items).ForEach(node => sc.Items.AddLast(node.Value));

                    sc.WithIdentity = s.WithIdentity;

                    newElement = sc;
                }

                break;
            }

            case EQueryElementType.UpdateClause:
            {
                var s = (IUpdateClause)element;
                var t = s.Table != null
                        ? (ISqlTable)ConvertInternal(s.Table, action)
                        : null;
                var i = Convert(s.Items, action);
                var k = Convert(s.Keys, action);

                if (t != null && !ReferenceEquals(s.Table, t) || i != null && !ReferenceEquals(s.Items, i) ||
                    k != null && !ReferenceEquals(s.Keys, k))
                {
                    var sc = new UpdateClause
                    {
                        Table = t ?? s.Table
                    };

                    (i ?? s.Items).ForEach(node => sc.Items.AddLast(node.Value));
                    (k ?? s.Keys).ForEach(node => sc.Keys.AddLast(node.Value));

                    newElement = sc;
                }

                break;
            }

            case EQueryElementType.DeleteClause:
            {
                var s = (IDeleteClause)element;
                var t = s.Table != null
                        ? (ISqlTable)ConvertInternal(s.Table, action)
                        : null;

                if (t != null && !ReferenceEquals(s.Table, t))
                {
                    newElement = new DeleteClause
                    {
                        Table = t
                    };
                }

                break;
            }

            case EQueryElementType.CreateTableStatement:
            {
                var s = (ICreateTableStatement)element;
                var t = s.Table != null
                        ? (ISqlTable)ConvertInternal(s.Table, action)
                        : null;

                if (t != null && !ReferenceEquals(s.Table, t))
                {
                    newElement = new CreateTableStatement
                    {
                        Table  = t,
                        IsDrop = s.IsDrop
                    };
                }

                break;
            }

            case EQueryElementType.SelectClause:
            {
                var sc   = (ISelectClause)element;
                var cols = Convert(sc.Columns, action);
                var take = (IQueryExpression)ConvertInternal(sc.TakeValue, action);
                var skip = (IQueryExpression)ConvertInternal(sc.SkipValue, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(sc.SelectQuery, out parent);

                if (parent != null || cols != null && !ReferenceEquals(sc.Columns, cols) ||
                    take != null && !ReferenceEquals(sc.TakeValue, take) ||
                    skip != null && !ReferenceEquals(sc.SkipValue, skip))
                {
                    newElement = new SelectClause(sc.IsDistinct, take ?? sc.TakeValue, skip ?? sc.SkipValue,
                                                  cols ?? sc.Columns);
                    ((ISelectClause)newElement).SetSqlQuery((ISelectQuery)parent);
                }

                break;
            }

            case EQueryElementType.FromClause:
            {
                var fc = (IFromClause)element;
                var ts = Convert(fc.Tables, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(fc.SelectQuery, out parent);

                if (parent != null || ts != null && !ReferenceEquals(fc.Tables, ts))
                {
                    newElement = new FromClause(ts ?? fc.Tables);
                    ((IFromClause)newElement).SetSqlQuery((ISelectQuery)parent);
                }

                break;
            }

            case EQueryElementType.WhereClause:
            {
                var wc   = (IWhereClause)element;
                var cond = (ISearchCondition)ConvertInternal(wc.Search, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(wc.SelectQuery, out parent);

                if (parent != null || cond != null && !ReferenceEquals(wc.Search, cond))
                {
                    newElement = new WhereClause(cond ?? wc.Search);
                    ((IWhereClause)newElement).SetSqlQuery((ISelectQuery)parent);
                }

                break;
            }

            case EQueryElementType.GroupByClause:
            {
                var gc = (IGroupByClause)element;
                var es = Convert(gc.Items, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(gc.SelectQuery, out parent);

                if (parent != null || es != null && !ReferenceEquals(gc.Items, es))
                {
                    newElement = new GroupByClause(es ?? gc.Items);
                    ((IGroupByClause)newElement).SetSqlQuery((ISelectQuery)parent);
                }

                break;
            }

            case EQueryElementType.OrderByClause:
            {
                var oc = (IOrderByClause)element;
                var es = Convert(oc.Items, action);

                IQueryElement parent;
                _visitedElements.TryGetValue(oc.SelectQuery, out parent);

                if (parent != null || es != null && !ReferenceEquals(oc.Items, es))
                {
                    newElement = new OrderByClause(es ?? oc.Items);
                    ((IOrderByClause)newElement).SetSqlQuery((ISelectQuery)parent);
                }

                break;
            }

            case EQueryElementType.OrderByItem:
            {
                var i = (IOrderByItem)element;
                var e = (IQueryExpression)ConvertInternal(i.Expression, action);

                if (e != null && !ReferenceEquals(i.Expression, e))
                {
                    newElement = new OrderByItem(e, i.IsDescending);
                }

                break;
            }

            case EQueryElementType.Union:
            {
                var u = (IUnion)element;
                var q = (ISelectQuery)ConvertInternal(u.SelectQuery, action);

                if (q != null && !ReferenceEquals(u.SelectQuery, q))
                {
                    newElement = new Union(q, u.IsAll);
                }

                break;
            }

            case EQueryElementType.SqlQuery:
            {
                var           q      = (ISelectQuery)element;
                IQueryElement parent = null;

                var doConvert = false;

                if (q.ParentSelect != null)
                {
                    if (!_visitedElements.TryGetValue(q.ParentSelect, out parent))
                    {
                        doConvert = true;
                        parent    = q.ParentSelect;
                    }
                }

                if (!doConvert)
                {
                    doConvert = null != FindFirstOrDefault <IQueryElement>(q, e =>
                        {
                            if (_visitedElements.ContainsKey(e) && _visitedElements[e] != e)
                            {
                                return(true);
                            }

                            var ret = action(e);

                            if (ret != null && !ReferenceEquals(e, ret))
                            {
                                _visitedElements.Add(e, ret);
                                return(true);
                            }

                            return(false);
                        });
                }

                if (!doConvert)
                {
                    break;
                }

                var nq = new SelectQuery
                {
                    EQueryType = q.EQueryType
                };

                _visitedElements.Add(q, nq);

                var fc = (IFromClause)ConvertInternal(q.From, action) ?? q.From;
                var sc = (ISelectClause)ConvertInternal(q.Select, action) ?? q.Select;
                var ic = q.IsInsert
                        ? ((IInsertClause)ConvertInternal(q.Insert, action) ?? q.Insert)
                        : null;
                var uc = q.IsUpdate
                        ? ((IUpdateClause)ConvertInternal(q.Update, action) ?? q.Update)
                        : null;
                var dc = q.IsDelete
                        ? ((IDeleteClause)ConvertInternal(q.Delete, action) ?? q.Delete)
                        : null;
                var wc = (IWhereClause)ConvertInternal(q.Where, action) ?? q.Where;
                var gc = (IGroupByClause)ConvertInternal(q.GroupBy, action) ?? q.GroupBy;
                var hc = (IWhereClause)ConvertInternal(q.Having, action) ?? q.Having;
                var oc = (IOrderByClause)ConvertInternal(q.OrderBy, action) ?? q.OrderBy;
                var us = q.HasUnion
                        ? Convert(q.Unions, action)
                        : q.Unions;

                var ps = new List <ISqlParameter>(q.Parameters.Count);

                foreach (var p in q.Parameters)
                {
                    IQueryElement e;

                    if (_visitedElements.TryGetValue(p, out e))
                    {
                        if (e == null)
                        {
                            ps.Add(p);
                        }
                        else
                        {
                            var sqlParameter = e as ISqlParameter;
                            if (sqlParameter != null)
                            {
                                ps.Add(sqlParameter);
                            }
                        }
                    }
                }

                nq.Init(ic, uc, dc, sc, fc, wc, gc, hc, oc, us, (ISelectQuery)parent, q.CreateTable,
                        q.IsParameterDependent, ps);

                _visitedElements[q] = action(nq) ?? nq;

                return(nq);
            }
            }

            newElement = newElement == null
                ? action(element)
                : (action(newElement) ?? newElement);

            _visitedElements.Add(element, newElement);

            return(newElement);
        }
Example #26
0
 /// <summary>
 /// 导出注册表信息中间过程。
 /// </summary>
 /// <param name="writer">
 /// XML写入控制器。
 /// </param>
 /// <param name="name">
 /// XML标记名。
 /// </param>
 protected new void MidExport(XmlTextWriter writer, string name)
 {
     base.MidExport(writer, name);
     writer.WriteAttributeString("isnull", AESCrypt.Encrypt(IsNull.ToString()));
     writer.WriteAttributeString("isnecessary", AESCrypt.Encrypt(IsNecessary.ToString()));
 }
Example #27
0
        public static ITag LoadTag(XNode node)
        {
            ITag tag = null;

            if (node.NodeType == System.Xml.XmlNodeType.Text || node.NodeType == System.Xml.XmlNodeType.CDATA)
            {
                tag = new SqlText
                {
                    BodyText = node.ToString()
                };
            }
            if (node.NodeType == System.Xml.XmlNodeType.Element)
            {
                XElement elenode      = node as XElement;
                bool     isIn         = elenode.Attribute("In") != null;
                var      prepend      = elenode.Attribute("Prepend")?.Value.Trim();
                var      property     = elenode.Attribute("Property")?.Value.Trim();
                var      compareValue = elenode.Attribute("CompareValue")?.Value.Trim();
                var      nodeName     = elenode.Name.LocalName;
                switch (nodeName)
                {
                case "IsEmpty":
                {
                    tag = new IsEmpty
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsEqual":
                {
                    tag = new IsEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsNotEqual":
                {
                    tag = new IsNotEqual
                    {
                        Prepend      = prepend,
                        CompareValue = compareValue,
                        Property     = property,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsGreaterEqual":
                {
                    tag = new IsGreaterEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                    };
                    break;
                }

                case "IsGreaterThan":
                {
                    tag = new IsGreaterThan
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsLessEqual":
                {
                    tag = new IsLessEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsLessThan":
                {
                    tag = new IsLessThan
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsNotEmpty":
                {
                    tag = new IsNotEmpty
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsNotNull":
                {
                    tag = new IsNotNull
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsNull":
                {
                    tag = new IsNull
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Switch":
                {
                    tag = new Switch
                    {
                        // Prepend = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Case":
                {
                    var switchNode     = node.Parent;
                    var switchProperty = switchNode.Attribute("Property")?.Value.Trim();
                    var switchPrepend  = switchNode.Attribute("Prepend")?.Value.Trim();
                    tag = new Switch.Case
                    {
                        Prepend      = switchPrepend,
                        Property     = switchProperty,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "Default":
                {
                    var switchNode     = node.Parent;
                    var switchProperty = switchNode.Attribute("Property")?.Value.Trim();
                    var switchPrepend  = switchNode.Attribute("Prepend")?.Value.Trim();
                    tag = new Switch.Default
                    {
                        Prepend  = switchPrepend,
                        Property = switchProperty,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Where":
                {
                    tag = new Where
                    {
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Dynamic":
                {
                    tag = new Dynamic
                    {
                        Prepend  = prepend,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsProperty":
                {
                    tag = new IsProperty
                    {
                        Prepend  = prepend,
                        Children = new List <ITag>(),
                        Property = property
                    };
                    break;
                }

                default:
                {
                    throw new BaraException($"Statement can't load TagName:{nodeName}");
                }
                }
                foreach (var childNode in elenode.Nodes())
                {
                    ITag childTag = LoadTag(childNode);
                    if (childTag != null && tag != null)
                    {
                        (tag as Tag).Children.Add(childTag);
                    }
                }
            }
            return(tag);
        }
Example #28
0
 public MySqlFunctionManager(bool allowFuncDefChange)
 {
     this.allowFuncDefChange                = allowFuncDefChange;
     parsingStrateg["CAST"]                 = FunctionParsingStrategy.Cast;
     parsingStrateg["POSITION"]             = FunctionParsingStrategy.Position;
     parsingStrateg["SUBSTR"]               = FunctionParsingStrategy.Substring;
     parsingStrateg["SUBSTRING"]            = FunctionParsingStrategy.Substring;
     parsingStrateg["TRIM"]                 = FunctionParsingStrategy.Trim;
     parsingStrateg["AVG"]                  = FunctionParsingStrategy.Avg;
     parsingStrateg["COUNT"]                = FunctionParsingStrategy.Count;
     parsingStrateg["GROUP_CONCAT"]         = FunctionParsingStrategy.GroupConcat;
     parsingStrateg["MAX"]                  = FunctionParsingStrategy.Max;
     parsingStrateg["MIN"]                  = FunctionParsingStrategy.Min;
     parsingStrateg["SUM"]                  = FunctionParsingStrategy.Sum;
     parsingStrateg["ROW"]                  = FunctionParsingStrategy.Row;
     parsingStrateg["CHAR"]                 = FunctionParsingStrategy.Char;
     parsingStrateg["CONVERT"]              = FunctionParsingStrategy.Convert;
     parsingStrateg["EXTRACT"]              = FunctionParsingStrategy.Extract;
     parsingStrateg["TIMESTAMPADD"]         = FunctionParsingStrategy.Timestampadd;
     parsingStrateg["TIMESTAMPDIFF"]        = FunctionParsingStrategy.Timestampdiff;
     parsingStrateg["GET_FORMAT"]           = FunctionParsingStrategy.GetFormat;
     functionPrototype["ABS"]               = new Abs(null);
     functionPrototype["ACOS"]              = new Acos(null);
     functionPrototype["ADDDATE"]           = new Adddate(null);
     functionPrototype["ADDTIME"]           = new Addtime(null);
     functionPrototype["AES_DECRYPT"]       = new AesDecrypt(null);
     functionPrototype["AES_ENCRYPT"]       = new AesEncrypt(null);
     functionPrototype["ANALYSE"]           = new Analyse(null);
     functionPrototype["ASCII"]             = new Ascii(null);
     functionPrototype["ASIN"]              = new Asin(null);
     functionPrototype["ATAN2"]             = new Atan2(null);
     functionPrototype["ATAN"]              = new Atan(null);
     functionPrototype["BENCHMARK"]         = new Benchmark(null);
     functionPrototype["BIN"]               = new Bin(null);
     functionPrototype["BIT_AND"]           = new BitAnd(null);
     functionPrototype["BIT_COUNT"]         = new BitCount(null);
     functionPrototype["BIT_LENGTH"]        = new BitLength(null);
     functionPrototype["BIT_OR"]            = new BitOR(null);
     functionPrototype["BIT_XOR"]           = new BitXor(null);
     functionPrototype["CEIL"]              = new Ceiling(null);
     functionPrototype["CEILING"]           = new Ceiling(null);
     functionPrototype["CHAR_LENGTH"]       = new CharLength(null);
     functionPrototype["CHARACTER_LENGTH"]  = new CharLength(null);
     functionPrototype["CHARSET"]           = new Charset(null);
     functionPrototype["COALESCE"]          = new Coalesce(null);
     functionPrototype["COERCIBILITY"]      = new Coercibility(null);
     functionPrototype["COLLATION"]         = new Collation(null);
     functionPrototype["COMPRESS"]          = new Compress(null);
     functionPrototype["CONCAT_WS"]         = new ConcatWs(null);
     functionPrototype["CONCAT"]            = new Concat(null);
     functionPrototype["CONNECTION_ID"]     = new ConnectionId(null);
     functionPrototype["CONV"]              = new Conv(null);
     functionPrototype["CONVERT_TZ"]        = new ConvertTz(null);
     functionPrototype["COS"]               = new Cos(null);
     functionPrototype["COT"]               = new Cot(null);
     functionPrototype["CRC32"]             = new Crc32(null);
     functionPrototype["CURDATE"]           = new Curdate();
     functionPrototype["CURRENT_DATE"]      = new Curdate();
     functionPrototype["CURRENT_TIME"]      = new Curtime();
     functionPrototype["CURTIME"]           = new Curtime();
     functionPrototype["CURRENT_TIMESTAMP"] = new Now();
     functionPrototype["CURRENT_USER"]      = new CurrentUser();
     functionPrototype["CURTIME"]           = new Curtime();
     functionPrototype["DATABASE"]          = new Database(null);
     functionPrototype["DATE_ADD"]          = new DateAdd(null);
     functionPrototype["DATE_FORMAT"]       = new DateFormat(null);
     functionPrototype["DATE_SUB"]          = new DateSub(null);
     functionPrototype["DATE"]              = new Date(null);
     functionPrototype["DATEDIFF"]          = new Datediff(null);
     functionPrototype["DAY"]               = new Dayofmonth(null);
     functionPrototype["DAYOFMONTH"]        = new Dayofmonth(null);
     functionPrototype["DAYNAME"]           = new Dayname(null);
     functionPrototype["DAYOFWEEK"]         = new Dayofweek(null);
     functionPrototype["DAYOFYEAR"]         = new Dayofyear(null);
     functionPrototype["DECODE"]            = new Decode(null);
     functionPrototype["DEFAULT"]           = new Default(null);
     functionPrototype["DEGREES"]           = new Degrees(null);
     functionPrototype["DES_DECRYPT"]       = new DesDecrypt(null);
     functionPrototype["DES_ENCRYPT"]       = new DesEncrypt(null);
     functionPrototype["ELT"]               = new Elt(null);
     functionPrototype["ENCODE"]            = new Encode(null);
     functionPrototype["ENCRYPT"]           = new Encrypt(null);
     functionPrototype["EXP"]               = new Exp(null);
     functionPrototype["EXPORT_SET"]        = new ExportSet(null);
     // functionPrototype.put("EXTRACT", new Extract(null));
     functionPrototype["EXTRACTVALUE"]  = new ExtractValue(null);
     functionPrototype["FIELD"]         = new Field(null);
     functionPrototype["FIND_IN_SET"]   = new FindInSet(null);
     functionPrototype["FLOOR"]         = new Floor(null);
     functionPrototype["FORMAT"]        = new Format(null);
     functionPrototype["FOUND_ROWS"]    = new FoundRows(null);
     functionPrototype["FROM_DAYS"]     = new FromDays(null);
     functionPrototype["FROM_UNIXTIME"] = new FromUnixtime(null);
     // functionPrototype.put("GET_FORMAT", new GetFormat(null));
     functionPrototype["GET_LOCK"]       = new GetLock(null);
     functionPrototype["GREATEST"]       = new Greatest(null);
     functionPrototype["HEX"]            = new Hex(null);
     functionPrototype["HOUR"]           = new Hour(null);
     functionPrototype["IF"]             = new IF(null);
     functionPrototype["IFNULL"]         = new IFNull(null);
     functionPrototype["INET_ATON"]      = new InetAton(null);
     functionPrototype["INET_NTOA"]      = new InetNtoa(null);
     functionPrototype["INSERT"]         = new Insert(null);
     functionPrototype["INSTR"]          = new Instr(null);
     functionPrototype["INTERVAL"]       = new Interval(null);
     functionPrototype["IS_FREE_LOCK"]   = new IsFreeLock(null);
     functionPrototype["IS_USED_LOCK"]   = new IsUsedLock(null);
     functionPrototype["ISNULL"]         = new IsNull(null);
     functionPrototype["LAST_DAY"]       = new LastDay(null);
     functionPrototype["LAST_INSERT_ID"] = new LastInsertId(null);
     functionPrototype["LCASE"]          = new Lower(null);
     functionPrototype["LEAST"]          = new Least(null);
     functionPrototype["LEFT"]           = new Left(null);
     functionPrototype["LENGTH"]         = new Length(null);
     functionPrototype["LN"]             = new Log(null);
     // Ln(X) equals Log(X)
     functionPrototype["LOAD_FILE"]       = new LoadFile(null);
     functionPrototype["LOCALTIME"]       = new Now();
     functionPrototype["LOCALTIMESTAMP"]  = new Now();
     functionPrototype["LOCATE"]          = new Locate(null);
     functionPrototype["LOG10"]           = new Log10(null);
     functionPrototype["LOG2"]            = new Log2(null);
     functionPrototype["LOG"]             = new Log(null);
     functionPrototype["LOWER"]           = new Lower(null);
     functionPrototype["LPAD"]            = new Lpad(null);
     functionPrototype["LTRIM"]           = new Ltrim(null);
     functionPrototype["MAKE_SET"]        = new MakeSet(null);
     functionPrototype["MAKEDATE"]        = new Makedate(null);
     functionPrototype["MAKETIME"]        = new Maketime(null);
     functionPrototype["MASTER_POS_WAIT"] = new MasterPosWait(null);
     functionPrototype["MD5"]             = new Md5(null);
     functionPrototype["MICROSECOND"]     = new Microsecond(null);
     functionPrototype["MID"]             = new Substring(null);
     functionPrototype["MINUTE"]          = new Minute(null);
     functionPrototype["MONTH"]           = new Month(null);
     functionPrototype["MONTHNAME"]       = new Monthname(null);
     functionPrototype["NAME_CONST"]      = new NameConst(null);
     functionPrototype["NOW"]             = new Now();
     functionPrototype["NULLIF"]          = new NullIF(null);
     functionPrototype["OCT"]             = new Oct(null);
     functionPrototype["OCTET_LENGTH"]    = new Length(null);
     functionPrototype["OLD_PASSWORD"]    = new OldPassword(null);
     functionPrototype["ORD"]             = new Ord(null);
     functionPrototype["PASSWORD"]        = new Password(null);
     functionPrototype["PERIOD_ADD"]      = new PeriodAdd(null);
     functionPrototype["PERIOD_DIFF"]     = new PeriodDiff(null);
     functionPrototype["PI"]              = new PI(null);
     functionPrototype["POW"]             = new Pow(null);
     functionPrototype["POWER"]           = new Pow(null);
     functionPrototype["QUARTER"]         = new Quarter(null);
     functionPrototype["QUOTE"]           = new Quote(null);
     functionPrototype["RADIANS"]         = new Radians(null);
     functionPrototype["RAND"]            = new Rand(null);
     functionPrototype["RELEASE_LOCK"]    = new ReleaseLock(null);
     functionPrototype["REPEAT"]          = new Repeat(null);
     functionPrototype["REPLACE"]         = new Replace(null);
     functionPrototype["REVERSE"]         = new Reverse(null);
     functionPrototype["RIGHT"]           = new Right(null);
     functionPrototype["ROUND"]           = new Round(null);
     functionPrototype["ROW_COUNT"]       = new RowCount(null);
     functionPrototype["RPAD"]            = new Rpad(null);
     functionPrototype["RTRIM"]           = new Rtrim(null);
     functionPrototype["SCHEMA"]          = new Database(null);
     functionPrototype["SEC_TO_TIME"]     = new SecToTime(null);
     functionPrototype["SECOND"]          = new Second(null);
     functionPrototype["SESSION_USER"]    = new User(null);
     functionPrototype["SHA1"]            = new Sha1(null);
     functionPrototype["SHA"]             = new Sha1(null);
     functionPrototype["SHA2"]            = new Sha2(null);
     functionPrototype["SIGN"]            = new Sign(null);
     functionPrototype["SIN"]             = new Sin(null);
     functionPrototype["SLEEP"]           = new Sleep(null);
     functionPrototype["SOUNDEX"]         = new Soundex(null);
     functionPrototype["SPACE"]           = new Space(null);
     functionPrototype["SQRT"]            = new Sqrt(null);
     functionPrototype["STD"]             = new Std(null);
     functionPrototype["STDDEV_POP"]      = new StdDevPop(null);
     functionPrototype["STDDEV_SAMP"]     = new StdDevSamp(null);
     functionPrototype["STDDEV"]          = new StdDev(null);
     functionPrototype["STR_TO_DATE"]     = new StrToDate(null);
     functionPrototype["STRCMP"]          = new Strcmp(null);
     functionPrototype["SUBDATE"]         = new Subdate(null);
     functionPrototype["SUBSTRING_INDEX"] = new SubstringIndex(null);
     functionPrototype["SUBTIME"]         = new Subtime(null);
     functionPrototype["SYSDATE"]         = new Sysdate(null);
     functionPrototype["SYSTEM_USER"]     = new User(null);
     functionPrototype["TAN"]             = new Tan(null);
     functionPrototype["TIME_FORMAT"]     = new TimeFormat(null);
     functionPrototype["TIME_TO_SEC"]     = new TimeToSec(null);
     functionPrototype["TIME"]            = new Time(null);
     functionPrototype["TIMEDIFF"]        = new Timediff(null);
     functionPrototype["TIMESTAMP"]       = new Timestamp(null);
     // functionPrototype.put("TIMESTAMPADD", new Timestampadd(null));
     // functionPrototype.put("TIMESTAMPDIFF", new Timestampdiff(null));
     functionPrototype["TO_DAYS"]             = new ToDays(null);
     functionPrototype["TO_SECONDS"]          = new ToSeconds(null);
     functionPrototype["TRUNCATE"]            = new Truncate(null);
     functionPrototype["UCASE"]               = new Upper(null);
     functionPrototype["UNCOMPRESS"]          = new Uncompress(null);
     functionPrototype["UNCOMPRESSED_LENGTH"] = new UncompressedLength(null);
     functionPrototype["UNHEX"]               = new Unhex(null);
     functionPrototype["UNIX_TIMESTAMP"]      = new UnixTimestamp(null);
     functionPrototype["UPDATEXML"]           = new UpdateXml(null);
     functionPrototype["UPPER"]               = new Upper(null);
     functionPrototype["USER"]          = new User(null);
     functionPrototype["UTC_DATE"]      = new UtcDate(null);
     functionPrototype["UTC_TIME"]      = new UtcTime(null);
     functionPrototype["UTC_TIMESTAMP"] = new UtcTimestamp(null);
     functionPrototype["UUID_SHORT"]    = new UuidShort(null);
     functionPrototype["UUID"]          = new Uuid(null);
     functionPrototype["VALUES"]        = new Values(null);
     functionPrototype["VAR_POP"]       = new VarPop(null);
     functionPrototype["VAR_SAMP"]      = new VarSamp(null);
     functionPrototype["VARIANCE"]      = new Variance(null);
     functionPrototype["VERSION"]       = new Version(null);
     functionPrototype["WEEK"]          = new Week(null);
     functionPrototype["WEEKDAY"]       = new Weekday(null);
     functionPrototype["WEEKOFYEAR"]    = new Weekofyear(null);
     functionPrototype["YEAR"]          = new Year(null);
     functionPrototype["YEARWEEK"]      = new Yearweek(null);
 }
Example #29
0
        public static ITag LoadTag(XmlNode xmlNode)
        {
            ITag tag          = null;
            bool isIn         = xmlNode.Attributes?["In"] != null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value;
            var  property     = xmlNode.Attributes?["Property"]?.Value;
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value;

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = xmlNode.InnerText.Replace("\n", "");
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value;
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value;
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default: { break; };
            }
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode);
                (tag as Tag).ChildTags.Add(childTag);
            }
            return(tag);
        }
Example #30
0
 /// <summary>
 ///   Creates the rule.
 /// </summary>
 /// <param name="target"> </param>
 /// <returns> </returns>
 public override RulePolicy CreateRule(object target)
 {
     Rule = new IsNull(RuleName, FailMessage, target);
     return(Rule);
 }
Example #31
0
        private ITag LoadTag(XNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            var  prepend      = xmlNode?.GetAttribute("Prepend")?.Trim();
            var  property     = xmlNode?.GetAttribute("Property")?.Trim();
            var  compareValue = xmlNode?.GetAttribute("CompareValue")?.Trim();

            #region Init Tag
            switch (xmlNode.GetName())
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.GetValue().Replace("\n", "").Trim();
                return(new SqlText
                    {
                        LineInfo = XmlLineInfo.Create(xmlNode),
                        BodyText = bodyText
                    });
            }

            case "If":
            {
                tag = new IfTag
                {
                    Test = xmlNode.GetAttribute("Test")
                };
                break;
            }

            case "Include":
            {
                var refId       = xmlNode?.GetAttribute("RefId");
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Bind":
            {
                tag = new BindTag
                {
                    Name  = xmlNode.GetAttribute("Name"),
                    Value = xmlNode.GetAttribute("Value"),
                };
                break;
            }

            case "Trim":
            {
                tag = new TrimTag
                {
                    Prefix          = xmlNode.GetAttribute("Prefix"),
                    PrefixOverrides = xmlNode.GetAttribute("PrefixOverrides"),
                    Suffix          = xmlNode.GetAttribute("Suffix"),
                    ChildTags       = new List <ITag>(),
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.Parent;
                var switchProperty = xmlNode?.GetAttribute("Property")?.Trim();
                var switchPrepend  = xmlNode?.GetAttribute("Prepend")?.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    Test         = xmlNode?.GetAttribute("Test")?.Trim(),
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.Parent;
                var switchProperty = xmlNode?.GetAttribute("Property")?.Trim();
                var switchPrepend  = xmlNode?.GetAttribute("Prepend")?.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode?.GetAttribute("Open")?.Trim();
                var separator = xmlNode?.GetAttribute("Separator")?.Trim();
                var close     = xmlNode?.GetAttribute("Close")?.Trim();
                var key       = xmlNode?.GetAttribute("Key")?.Trim();
                var index     = xmlNode?.GetAttribute("Index")?.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Index     = index,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode?.GetAttribute("DbProvider")?.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.GetName()}.");
            };
            }
            #endregion
            if (tag != null)
            {
                tag.LineInfo = XmlLineInfo.Create(xmlNode);
            }
            if (xmlNode is XElement ell)
            {
                foreach (XNode childNode in ell.Nodes())
                {
                    ITag childTag = LoadTag(childNode, includes);
                    if (childTag != null && tag != null)
                    {
                        childTag.Parent = tag;
                        (tag as Tag).ChildTags.Add(childTag);
                    }
                }
            }
            return(tag);
        }