Example #1
0
 public Energy.Query.Parameter.Bag Add(string name, object value, string format)
 {
     Energy.Enumeration.FormatType type = Energy.Base.Cast.StringToEnum <Energy.Enumeration.FormatType>(format);
     SetValue(name, value);
     SetType(name, type);
     return(this);
 }
Example #2
0
 public Energy.Query.Parameter.Bag Add(string name, object value)
 {
     Energy.Enumeration.FormatType type = Energy.Enumeration.FormatType.Text;
     SetValue(name, value);
     SetType(name, type);
     return(this);
 }
Example #3
0
 public Energy.Query.Parameter.Bag SetType(string name, Energy.Enumeration.FormatType type)
 {
     if (null == name)
     {
         return(this);
     }
     if (!name.StartsWith("@"))
     {
         name = "@" + name;
     }
     _Types[name] = type;
     return(this);
 }
Example #4
0
            /// <summary>
            /// Parse parametrized query string.
            /// </summary>
            /// <param name="query"></param>
            /// <returns></returns>
            public string Parse(string query)
            {
                if (string.IsNullOrEmpty(query))
                {
                    return(query);
                }

                bool optionUnicode        = this.Unicode;
                bool optionUnknownAsEmpty = this.UnknownAsEmpty;
                bool optionUnknownAsNull  = this.UnknownAsNull;
                bool optionNullAsZero     = this.NullAsZero;

                bool allowUnknow = optionUnknownAsEmpty || optionUnknownAsNull;

                Energy.Query.Format format = _Format ?? Energy.Query.Format.Default;

                RegexOptions regexOptions  = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace;
                Regex        regexVariable = new Regex(patternVariable, regexOptions);
                int          Δ             = 0;

                foreach (Match matchVariable in regexVariable.Matches(query))
                {
                    string name = matchVariable.Groups["name"].Value;
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    string value;

                    if (Contains(name))
                    {
                        object o = GetValue(name);
                        Energy.Enumeration.FormatType f = GetType(name);
                        if (optionNullAsZero && o == null)
                        {
                            o = 0;
                        }
                        value = format.Value(o, f, optionUnicode);
                    }
                    else if (!allowUnknow)
                    {
                        continue;
                    }
                    else if (name.StartsWith("@@"))
                    {
                        continue;
                    }
                    else if (optionUnknownAsEmpty)
                    {
                        value = format.Text("");
                    }
                    else if (optionNullAsZero)
                    {
                        value = "0";
                    }
                    else
                    {
                        value = "NULL";
                    }

                    int p = matchVariable.Index;
                    int l = matchVariable.Length;
                    query = ""
                            + (p + Δ > 0 ? query.Substring(0, p + Δ) : "")
                            + value
                            + query.Substring(p + l + Δ)
                    ;
                    Δ += value.Length - l;
                }
                return(query);
            }