Ejemplo n.º 1
0
 protected virtual string GetSqlExpression(PropertyElement p)
 {
     return(p.GetSqlExpression());
 }
Ejemplo n.º 2
0
 protected override string GetSqlExpression(PropertyElement p)
 {
     return(p.GetSqlExpression(true));
 }
Ejemplo n.º 3
0
        /*
         * /// <summary>
         * /// Replaces embedded property references in the string with sql cocde.
         * /// </summary>
         * /// <param name="withEmbedded">Expression to be replaced.</param>
         * /// <param name="idString">Id to use when reporting errors.</param>
         * /// <param name="vd">Validation delegate for error reporting.</param>
         * /// <returns>String with embedded references replaced.</returns>
         * private string PrepareExpression(string withEmbedded, string idString, ParserValidationDelegate vd)
         * {
         *  string checkExpression = withEmbedded;
         *  string retVal = String.Empty;
         *  int leftBrace = 0;
         *  int startPos = 0;
         *  for(leftBrace=checkExpression.IndexOf("{", startPos); startPos >=0; leftBrace=checkExpression.IndexOf("{", startPos))
         *  {
         *      if (leftBrace == -1)
         *      {
         *          // No more strings to replace.
         *          retVal += checkExpression.Substring(startPos, checkExpression.Length - startPos);
         *          break;
         *      }
         *      else
         *      {
         *          // Concatenate portion of string without embedded references.
         *          retVal += checkExpression.Substring(startPos, leftBrace - startPos);
         *      }
         *      int rightBrace = checkExpression.IndexOf("}", leftBrace);
         *      if (rightBrace == -1)
         *      {
         *          if (vd != null)
         *          {
         *              vd(ParserValidationArgs.NewError("The " + idString + " has a left brace({} with no corresonding right brace(}}"));
         *          }
         *          return "";
         *      }
         *
         *      // Isolate the property reference.
         *      string expression = checkExpression.Substring(leftBrace+1, rightBrace - leftBrace - 1);
         *
         *      // Create list of property references seen to check for circular references.
         *      ArrayList repeList = new ArrayList();
         *
         *      string[] parts = expression.Split('.');
         *      string leftPart = "";
         *      string rightPart = "";
         *      if (parts.Length == 1)
         *      {
         *          // Default the left part to this report extraction if not specified.
         *          leftPart = this.Name;
         *          rightPart = parts[0];
         *      }
         *      else if (parts.Length == 2)
         *      {
         *          leftPart = parts[0];
         *          rightPart = parts[1];
         *      }
         *      else
         *      {
         *          if (vd != null)
         *          {
         *              vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " does not contain exactly one dot(.)."));
         *          }
         *          return "";
         *      }
         *
         *
         *      if (leftPart.ToLower() == this.Name.ToLower())
         *      {
         *          // Refers to a property in this report extraction.
         *          ReportExtractionPropertyElement repe = this.FindComputedFieldByName(rightPart);
         *          if (repe != null)
         *          {
         *              // Refers to a computed property.  Check for circular references.
         *              foreach(ReportExtractionPropertyElement repel in repeList)
         *              {
         *                  if(repel.Name == repe.Name)
         *                  {
         *                      if (vd != null)
         *                      {
         *                          vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " has a circular reference."));
         *                      }
         *                      return "";
         *                  }
         *              }
         *
         *              // Add in the expansion of this property.e
         *              retVal += "(" + repe.GetSqlExpression() + ")";
         *          }
         *          else
         *          {
         *              EntityReferencePropertyElement pre = this.FindReferenceFieldByName(rightPart);
         *              if (pre != null)
         *              {
         *                  // Refers to a property reference.  Get the expression.
         *                  retVal += pre.GetSqlExpression();
         *              }
         *              else
         *              {
         *                  if (vd != null)
         *                  {
         *                      vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property in the report extraction that does not exist."));
         *                  }
         *                  return "";
         *              }
         *          }
         *      }
         *      else
         *      {
         *          EntityReferenceElement er = FindEntityReferenceByName(leftPart);
         *          if (er == null)
         *          {
         *              if (vd != null)
         *              {
         *                  vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself."));
         *              }
         *              return "";
         *          }
         *          else
         *          {
         *              // Refers to an entity reference.
         *              EntityReferencePropertyElement pre = er.FindFieldBySqlAlias(rightPart);
         *              if (pre != null)
         *              {
         *                  // Refers to a property reference in the entity.
         *                  retVal += pre.GetSqlExpression();
         *              }
         *              else
         *              {
         *                  PropertyElement p = er.Entity.FindFieldByName(rightPart);
         *                  if (p != null)
         *                  {
         *                      // Refers to a property in the entity referenced that is not in the property referenced.
         *                      retVal += "[" + er.Name + "].[" + p.Column.Name + "]";
         *                  }
         *                  else
         *                  {
         *                      if (vd != null)
         *                      {
         *                          vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity."));
         *                      }
         *                      else
         *                      {
         *                          return "";
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *
         *      startPos = rightBrace + 1;
         *  }
         *
         *  return retVal;
         * }*/

        public string GetExpressionSubstitution(string substitutionExpression, string idString, ParserValidationDelegate vd)
        {
            // Create list of property references seen to check for circular references.
            ArrayList repeList = new ArrayList();

            string[] parts     = substitutionExpression.Split('.');
            string   leftPart  = "";
            string   rightPart = "";

            if (parts.Length == 1)
            {
                // Default the left part to this report extraction if not specified.
                leftPart  = this.Name;
                rightPart = parts[0];
            }
            else if (parts.Length == 2)
            {
                leftPart  = parts[0];
                rightPart = parts[1];
            }
            else
            {
                if (vd != null)
                {
                    vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " does not contain exactly one dot(.)."));
                }
                return("");
            }


            if (leftPart.ToLower() == this.Name.ToLower())
            {
                // Refers to a property in this report extraction.
                PropertyElement repe = this.FindComputedFieldByName(rightPart);
                if (repe != null)
                {
                    // Refers to a computed property.  Check for circular references.
                    foreach (PropertyElement repel in repeList)
                    {
                        if (repel.Name == repe.Name)
                        {
                            if (vd != null)
                            {
                                vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " has a circular reference."));
                            }
                            return("");
                        }
                    }

                    // Add in the expansion of this property.e
                    return("(" + repe.GetSqlExpression() + ")");
                }
                else
                {
                    PropertyElement pre = this.FindReferenceFieldByName(rightPart);
                    if (pre != null)
                    {
                        // Refers to a property reference.  Get the expression.
                        return(pre.GetSqlExpression());
                    }
                    else
                    {
                        if (vd != null)
                        {
                            vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property in the report extraction that does not exist."));
                        }
                        return("");
                    }
                }
            }
            else
            {
                EntityReferenceElement er = FindEntityReferenceByName(leftPart);
                if (er == null)
                {
                    if (vd != null)
                    {
                        vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself."));
                    }
                    return("");
                }
                else
                {
                    // Refers to an entity reference.
                    PropertyElement pre = er.FindFieldBySqlAlias(rightPart);
                    if (pre != null)
                    {
                        // Refers to a property reference in the entity.
                        return(pre.GetSqlExpression());
                    }
                    else
                    {
                        PropertyElement p = er.Entity.FindFieldByName(rightPart);
                        if (p != null)
                        {
                            // Refers to a property in the entity referenced that is not in the property referenced.
                            return("[" + er.Name + "].[" + p.Column.Name + "]");
                        }
                        else
                        {
                            if (vd != null)
                            {
                                vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity."));
                            }
                            return("");
                        }
                    }
                }
            }
        }