private bool GetFunction(out TParserFunc AValue)
        {
            string TmpStr;
            bool   Result = false;

            AValue = TParserFunc.pfArcTan;
            if (IsLetter(FParseText[FCurPos]))
            {
                foreach (TParserFunc func in FuncNames.Keys)
                {
                    TmpStr = FParseText.Substring(FCurPos, FuncNames[func].Length);
                    if (TmpStr.CompareTo(FuncNames[func]) == 0)
                    {
                        AValue = func;
                        if (FParseText[FCurPos + TmpStr.Length] == '(')
                        {
                            Result   = true;
                            FCurPos += TmpStr.Length;
                            break;
                        }
                    }
                } //end foreach
            }     //end if
            return(Result);
        }
Exemple #2
0
        public async Task Exec(IScenarioContext context)
        {
            string[] values =
            {
                "Some simple text",
                "a%b%c",
                "aabcc"
            };

            var table = new TmpStr();
            await context.Database.Statement(table.Script.Create());

            await InsertDataInto(table, values).MapData(s => s.Set(s.Target.Index, s.Index).Set(s.Target.Text, s.Source)).Exec(context.Database);

            var res = await Find("%simple%");

            AssertResult(res, 0);

            res = await Find(context.Dialect == SqlDialect.TSql? "a[%]b[%]c" : "a\\%b\\%c");

            AssertResult(res, 1);

            res = await Find("a%b%c");

            AssertResult(res, 1, 2);

            await context.Database.Statement(table.Script.Drop());

            Task <List <int> > Find(string pattern)
            {
                return(Select(table.Index)
                       .From(table)
                       .Where(Like(table.Text, pattern))
                       .OrderBy(table.Index)
                       .QueryList(context.Database, r => table.Index.Read(r)));
            }

            void AssertResult(IReadOnlyList <int> result, params int[] expected)
            {
                if (result.Count != expected.Length)
                {
                    throw new Exception($"{context.Dialect}: search is incorrect: expected length: {expected.Length} but was {result.Count}");
                }

                for (int i = 0; i < result.Count; i++)
                {
                    if (result[i] != expected[i])
                    {
                        throw new Exception($"{context.Dialect}: Search is incorrect: expected value: {expected[i]} but was {result[i]}");
                    }
                }
            }
        }
        private bool GetUserFunction(ref string fname)
        {
            string TmpStr;
            bool   Result = false;

            if (IsLetter(FParseText[FCurPos]) && UserFuncList.Count > 0)
            {
                foreach (string funcName in UserFuncList.Keys)
                {
                    TmpStr = FParseText.Substring(FCurPos, funcName.Length);
                    if (TmpStr.CompareTo(funcName) == 0 && UserFuncList[funcName] != null)
                    {
                        if (FParseText[FCurPos + TmpStr.Length] == '(')
                        {
                            Result   = true;
                            FCurPos += TmpStr.Length;
                            fname    = funcName;
                            return(Result);
                        }
                    }
                }//end foreach
            }
            return(Result);
        }
      public string GetFldCriteriaLmt(string FieldName, string Criteria, bool GetMax)
      {
          int i, k1, k2;

          string   TmpStr, CmpStr = "";
          DateTime Udate = new DateTime();
          DateTime Ldate = new DateTime();

          i = 0;
          LOP :;
          //i = InStr(i + 1, Criteria, FieldName, vbTextCompare)

          i = (Criteria.IndexOf(FieldName, i + 1, StringComparison.OrdinalIgnoreCase));

          if (i > 0)
          {
              k1 = (Criteria.IndexOf("\'", (i - 1)) + 1);
              k2 = (Criteria.IndexOf("\'", k1) + 1);
              if (k1 == 0 | k2 == 0)
              {
                  goto LOP;
              }
              TmpStr = Criteria.Substring(k1, (k2 - (k1 - 1)));
              DateTime d = new DateTime(int.Parse(TmpStr.Substring(6, 4)), int.Parse(TmpStr.Substring(0, 2)), int.Parse(TmpStr.Substring(3, 2)));
              //CmpStr = Trim(Replace(Replace(Mid(Criteria, i + Len(FieldName), k1 - (i + Len(FieldName))), "(", ""), ")", ""))
              CmpStr = Criteria.Substring(i + FieldName.Length, k1 - (i + FieldName.Length));
              CmpStr = CmpStr.Replace("(", "");
              CmpStr = CmpStr.Replace(")", "");
              CmpStr = CmpStr.Trim();
              switch (CmpStr)
              {
              case "<":
              {
                  if (d > Udate | Udate == default(DateTime))
                  {
                      Udate = DateTime.Now.AddDays(-1);
                  }
                  break;
              }

              case "<=":
              {
                  if (d > Udate | Udate == default(DateTime))
                  {
                      Udate = d;
                  }
                  break;
              }

              case "=":
              {
                  Udate = d; Ldate = d;
                  break;
              }

              case ">":
              {
                  if (d < Ldate | Ldate == default(DateTime))
                  {
                      Ldate = DateTime.Now.AddDays(1);
                  }
                  break;
              }

              case ">=":
              {
                  if (d < Ldate | Ldate == default(DateTime))
                  {
                      Ldate = d;
                  }
                  break;
              }
              }
              goto LOP;
          }
          if (GetMax)
          {
              if (Udate == default(DateTime))
              {
                  return("");
              }
              else
              {
                  return(string.Format("MM/dd/yyyy", Udate));
              }
          }
          else if (Ldate == default(DateTime))
          {
              return("");
          }
          else
          {
              return(string.Format("MM/dd/yyyy", Ldate));
          }
      }