Beispiel #1
0
        public string ToSql(DbEngine dbEngine, ModelInfo modelInfo)
        {
            string joinStr = "JOIN";
            switch (Type)
            {
                case JoinType.INNER:
                    break;
                case JoinType.RIGHT_OUTER:
                    joinStr = "RIGHT " + joinStr;
                    break;
                case JoinType.LEFT_OUTER:
                    joinStr = "LEFT " + joinStr;
                    break;
                case JoinType.FULL_OUTER:
                    joinStr = "FULL OUTER " + joinStr;
                    break;
                default:
                    break;
            }

            return string.Format(" {0} {1} as {2} ON {2}.{3} = {4}.{5}{6}",
                joinStr,
                JoinedModel.ModelDbName,
                JoinedModel.ModelDbAlias,
                JoinedField,
                modelInfo.ModelDbAlias,
                ModelField,
                JoinConditions != null ? " AND " + JoinConditions.ToWhereClause(dbEngine, JoinedModel) : "");
        }
Beispiel #2
0
 public string GetWhereClause(DbEngine dbEngine)
 {
     if (WhereExpressions == null || WhereExpressions.IsEmpty)
         return string.Empty;
     return " WHERE " + WhereExpressions.ToWhereClause(dbEngine, _manager.ModelInfo);
 }
Beispiel #3
0
        public string ToWhereClause(DbEngine dbEngine, IModel model)
        {
            StringBuilder sb = new StringBuilder();
            int exprCount = Expressions.Count;
            sb.Append(" ");

            for (int i = 0; i < exprCount; i++)
            {
                QExpr expr = Expressions[i];
                if (i > 0)
                    sb.Append(_GROUP_OPERATOR_FORMATTED);

                string paramValue = null;
                if (expr.Operator != Constants.QueryCompareOps.IN)
                    paramValue = expr.QParam.Id;
                else
                {
                    IEnumerable arr = expr.RHS as IEnumerable;
                    if (arr != null)
                    {
                        int objIndex = 0;
                        paramValue = "(";
                        foreach (object obj in arr)
                        {
                            if (objIndex > 0)
                                paramValue += ",";
                            paramValue += dbEngine.ToSqlFormat(Fields.FieldType.Custom, obj);
                            objIndex++;
                        }
                        paramValue += ")";
                    }
                }

                sb.AppendFormat("{0}.{1} {2} {3}",
                    model.ModelDbAlias,
                    Constants.QueryCompareOps.TransformLHS(expr.Operator, expr.LHS, dbEngine),
                    Constants.QueryCompareOps.ToSql(expr.Operator),
                    paramValue);

            }

            for (int i = 0; i < SubGroups.Count; i++)
            {
                QExprGroup qcg = SubGroups[i];
                if (exprCount > 0 || i > 0)
                    sb.Append(_GROUP_OPERATOR_FORMATTED);
                sb.AppendFormat("({0})", qcg.ToWhereClause(dbEngine, model));
            }

            if (Negated)
                return "NOT(" + sb.ToString() + ")";
            else
                return sb.ToString();
        }
Beispiel #4
0
        public string GetJoins(DbEngine dbEngine)
        {
            StringBuilder sb = new StringBuilder();
            foreach (QueryJoin join in _joins)
            {
                sb.Append(join.ToSql(dbEngine, _manager.ModelInfo));
            }

            return sb.ToString();
        }
Beispiel #5
0
            public static object TransformLHS(string op, object value, DbEngine dbEngine)
            {
                if(value != null && (op == ICONTAINS || op == ISTARTSWITH || op == IENDSWITH))
                    return string.Format("{0}({1})", dbEngine.GetFunction(DbFunctions.ToLower), value);

                return value;
            }