IQMap.Impl.Support.ParameterParser.GetWhereClause C# (CSharp) Method

GetWhereClause() public method

public GetWhereClause ( ) : IWhere
return IWhere
        public IWhere GetWhereClause()
        {
            // In some situations, the query has already been built.
            if (WhereClause == null)
            {
                return QueryBuilder.WhereParse(Query, Parameters);
            }
            else
            {
                return WhereClause;
            }
        }

Usage Example

Example #1
0
        protected ISqlQuery ParseComplexQuery(object query, IEnumerable <object> parms)
        {
            ISqlQuery outputQuery = null;

            // We always want to parse the parameters. But if the thing passed to us as "query" is not a string, then
            // just assume that all the parms are option type parameters and don't pass a query to ParameterParser
            string querySource = query is string?
                                 (string)query:
                                 "";

            ParameterParser pp = new ParameterParser(querySource, parms);

            if (Types.IsNumericType(query))
            {
                // It's a single numeric value - assume it's a primary key

                ExpectNoParameters(pp.Parameters);

                var classInfo = IQ.ClassInfo <T>();

                ISqlQueryMaker queryPK = classInfo.GetQuery();
                queryPK.Where.Add(classInfo.PrimaryKeyField.Name, query);
                outputQuery = queryPK;
            }
            else if (query is string)
            {
                bool isMappable = Types.IsMappable(typeof(T));

                // First check if its a single named field

                if (isMappable)
                {
                    var classInfo = IQ.ClassInfo <T>();


                    // Try to create a valid raw query.. if it's not valid, assume it's a where
                    if (QueryType == QueryType.Where || pp.QueryType == QueryType.Invalid)
                    {
                        ISqlQueryMaker queryPK = classInfo.GetQuery();

                        //var whereString = new WhereString(pp.Query,
                        //    pp.Parameters.Count > 0 ?
                        //        pp.Parameters.ToArray():
                        //        null);
                        queryPK.Where.Add(pp.GetWhereClause());

                        outputQuery = queryPK;
                    }
                    else
                    {
                        outputQuery = new SqlQueryDef(pp.GetQuery(QueryType), pp.Parameters);
                    }
                }
                else
                {
                    // it's mapped to a primitive type -
                    outputQuery = new SqlQueryDef(pp.GetQuery(QueryType), pp.Parameters);
                }
            }
            if (outputQuery.QueryType != QueryType)
            {
                throw new IQException("Wrong type of query passed to method: was " + outputQuery.ToString() + ", expected " + QueryType.ToString());
            }

            return(outputQuery);
        }