示例#1
0
        public override SqlFragment Visit(DbArithmeticExpression expression)
        {
            if (expression.ExpressionKind == DbExpressionKind.UnaryMinus)
            {
                ListFragment f = new ListFragment();
                f.Append("-(");
                f.Append(expression.Arguments[0].Accept(this));
                f.Append(")");
                return(f);
            }

            string op = String.Empty;

            switch (expression.ExpressionKind)
            {
            case DbExpressionKind.Divide:
                op = "/"; break;

            case DbExpressionKind.Minus:
                op = "-"; break;

            case DbExpressionKind.Modulo:
                op = "%"; break;

            case DbExpressionKind.Multiply:
                op = "*"; break;

            case DbExpressionKind.Plus:
                op = "+"; break;

            default:
                throw new NotSupportedException();
            }
            return(VisitBinaryExpression(expression.Arguments[0], expression.Arguments[1], op));
        }
        protected override SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning)
        {
            SelectStatement select = base.GenerateReturningSql(tree, returning);

            ListFragment where = new ListFragment();
            where.Append(" row_count() = 1 and (");
            where.Append(((DbUpdateCommandTree)tree).Predicate.Accept(this));
            where.Append(")");
            select.Where = where;

            return(select);
        }
示例#3
0
        protected virtual SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning)
        {
            SelectStatement select = new SelectStatement(this);

            Debug.Assert(returning is DbNewInstanceExpression);
            VisitNewInstanceExpression(select, returning as DbNewInstanceExpression);

            select.From = (InputFragment)tree.Target.Expression.Accept(this);

            ListFragment where = new ListFragment();
            select.Where       = where;
            return(select);
        }
示例#4
0
        protected virtual SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning)
        {
            SelectStatement select = base.GenerateReturningSql(tree, returning);

            ListFragment where = new ListFragment();

            EntitySetBase table         = ((DbScanExpression)tree.Target.Expression).Target;
            bool          foundIdentity = false;

            where.Append(" row_count() > 0");
            foreach (EdmMember keyMember in table.ElementType.KeyMembers)
            {
                SqlFragment value;
                if (!values.TryGetValue(keyMember, out value))
                {
                    if (foundIdentity)
                    {
                        throw new NotSupportedException();
                    }
                    foundIdentity = true;
                    PrimitiveTypeKind type = ((PrimitiveType)keyMember.TypeUsage.EdmType.BaseType).PrimitiveTypeKind;
                    if ((type == PrimitiveTypeKind.Byte) || (type == PrimitiveTypeKind.SByte) ||
                        (type == PrimitiveTypeKind.Int16) || (type == PrimitiveTypeKind.Int32) ||
                        (type == PrimitiveTypeKind.Int64) || (type == PrimitiveTypeKind.Decimal && IsValidMySqlDataType(keyMember.TypeUsage.EdmType.FullName)))
                    {
                        value = new LiteralFragment("last_insert_id()");
                    }
                    else if (keyMember.TypeUsage.EdmType.BaseType.Name == "Guid")
                    {
                        value = new LiteralFragment(string.Format("ANY(SELECT guid FROM tmpIdentity_{0})", (table as MetadataItem).MetadataProperties["Table"].Value));
                    }
                }
                where.Append(String.Format(" AND `{0}`=", keyMember));
                where.Append(value);
            }
            select.Where = where;
            return(select);
        }
        private SqlFragment UserDefinedFunction(DbFunctionExpression e)
        {
            FunctionFragment f = new FunctionFragment();

            f.Name = Metadata.TryGetValueMetadataProperty <string>(e.Function,
                                                                   "StoreFunctionNameAttribute");

            if (String.IsNullOrEmpty(f.Name))
            {
                f.Name = e.Function.Name;
            }

            f.Quoted = !Metadata.TryGetValueMetadataProperty <bool>(e.Function, "BuiltInAttribute");

            bool isFuncNiladic = Metadata.TryGetValueMetadataProperty <bool>(e.Function, "NiladicFunctionAttribute");

            if (isFuncNiladic && e.Arguments.Count > 0)
            {
                throw new InvalidOperationException("Niladic functions cannot have parameters");
            }

            ListFragment list      = new ListFragment();
            string       delimiter = "";

            foreach (DbExpression arg in e.Arguments)
            {
                if (delimiter.Length > 0)
                {
                    list.Append(new LiteralFragment(delimiter));
                }
                list.Append(arg.Accept(callingGenerator));
                delimiter = ", ";
            }
            f.Argument = list;

            return(f);
        }
示例#6
0
 public void Visit(ListFragment f)
 {
 }