Ejemplo n.º 1
0
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
            {
                if (Mode == SqlProvider.ProviderMode.Oracle)
                {
                    sb.Append(spc.Function.MappedName);
                }
                else
                {
                    sb.Append("begin ");
                    var returnType = spc.Function.Method.ReturnType;
                    if (returnType != typeof(void))
                    {
                        sb.Append(":RETURN_VALUE := ");
                    }

                    WriteName(spc.Function.MappedName);
                    sb.Append("(");
                    int count = spc.Function.Parameters.Count;
                    for (int i = 0; i < count; i++)
                    {
                        MetaParameter parameter = spc.Function.Parameters[i];
                        if (i > 0)
                        {
                            sb.Append(", ");
                        }
                        Visit(spc.Arguments[i]);
                    }
                    sb.Append("); ");
                    sb.Append("end;");
                }
                return(spc);
            }
Ejemplo n.º 2
0
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
            {
                this.VisitUserQuery(spc);
                int num   = 0;
                int count = spc.Function.Parameters.Count;

                while (num < count)
                {
                    MetaParameter p    = spc.Function.Parameters[num];
                    var           node = spc.Arguments[num] as SqlParameter;
                    if (node != null)
                    {
                        node.Direction = GetParameterDirection(p);
                        Debug.Assert(!string.IsNullOrEmpty(p.MappedName));
                        node.Name = p.MappedName;
                        if ((node.Direction == ParameterDirection.InputOutput) ||
                            (node.Direction == ParameterDirection.Output))
                        {
                            RetypeOutParameter(node);
                        }
                    }
                    num++;
                }
                //var parameter3 = new SqlParameter(typeof(int?),
                //                                  parameterizer.TypeProvider.From(typeof(int)),
                //                                  "@RETURN_VALUE", spc.SourceExpression) { Direction = ParameterDirection.Input };
                //this.currentParams.Add(new SqlParameterInfo(parameter3));
                return(spc);
            }
Ejemplo n.º 3
0
        internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
        {
            this.VisitUserQuery(spc);

            for (int i = 0, n = spc.Function.Parameters.Count; i < n; i++)
            {
                MetaParameter mp  = spc.Function.Parameters[i];
                SqlParameter  arg = spc.Arguments[i] as SqlParameter;
                if (arg != null)
                {
                    arg.Direction = this.GetParameterDirection(mp);
                    if (arg.Direction == ParameterDirection.InputOutput ||
                        arg.Direction == ParameterDirection.Output)
                    {
                        // Text, NText and Image parameters cannot be used as output parameters
                        // so we retype them if necessary.
                        RetypeOutParameter(arg);
                    }
                }
            }

            // add default return value
            SqlParameter p = new SqlParameter(typeof(int?), this.parameterizer.TypeProvider.From(typeof(int)), "@RETURN_VALUE", spc.SourceExpression);

            p.Direction = Data.ParameterDirection.Output;
            this.currentParams.Add(new SqlParameterInfo(p));

            return(spc);
        }
Ejemplo n.º 4
0
 internal virtual SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc) {
     for (int i = 0, n = spc.Arguments.Count; i < n; i++) {
         spc.Arguments[i] = this.VisitExpression(spc.Arguments[i]);
     }
     spc.Projection = this.VisitExpression(spc.Projection);
     for (int i = 0, n = spc.Columns.Count; i < n; i++) {
         spc.Columns[i] = (SqlUserColumn) this.Visit(spc.Columns[i]);
     }
     return spc;
 }
Ejemplo n.º 5
0
            //private int index = 0;
            //internal override string CreateParameterName()
            //{
            //    return (FirebirdIdentifier.Instance.ParameterPrefix + "p" + index++);
            //}
            #region MyRegion
            //internal override SqlParameter InsertLookup(SqlValue cp)
            //{
            //    SqlParameterInfo info;
            //    if (!map.TryGetValue(cp, out info))
            //    {
            //        var parameterName = cp.Value == null ? "NULL" : CreateParameterName();
            //        var parameter = new SqlParameter(cp.ClrType, cp.SqlType,
            //                                         parameterName,
            //                                         cp.SourceExpression);
            //        info = new SqlParameterInfo(parameter, cp.Value);
            //        map.Add(cp, info);
            //        currentParams.Add(info);
            //    }
            //    return info.Parameter;
            //}
            #endregion

            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
            {
                VisitUserQuery(spc);
                int num   = 0;
                int count = spc.Function.Parameters.Count;

                while (num < count)
                {
                    MetaParameter p    = spc.Function.Parameters[num];
                    var           node = spc.Arguments[num] as SqlParameter;
                    if (node != null)
                    {
                        node.Direction = GetParameterDirection(p);
                        Debug.Assert(!string.IsNullOrEmpty(p.MappedName));
                        node.Name = p.MappedName;
                        if ((node.Direction == ParameterDirection.InputOutput) ||
                            (node.Direction == ParameterDirection.Output))
                        {
                            RetypeOutParameter(node);
                        }
                    }
                    num++;
                }

                var returnType = spc.Function.Method.ReturnType;

                if (returnType != typeof(void))
                {
                    if (returnType.IsValueType || returnType == typeof(string))
                    {
                        IProviderType paramType = parameterizer.TypeProvider.From(returnType);

                        var parameter3 = new SqlParameter(returnType, paramType, ":RETURN_VALUE", spc.SourceExpression)
                        {
                            Direction = ParameterDirection.Output
                        };
                        currentParams.Add(new SqlParameterInfo(parameter3));
                    }
                    //else if (returnType.IsGenericType &&
                    //        ((returnType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
                    //         (returnType.GetGenericTypeDefinition() == typeof(ISingleResult<>))))
                    //{
                    //    //paramType = parameterizer.TypeProvider.From(typeof(OracleRefCursor));
                    //}
                    //else
                    //{
                    //    throw SqlClient.Error.InvalidReturnFromSproc(returnType);
                    //}
                }

                return(spc);
            }
Ejemplo n.º 6
0
        internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
        {
            List <SqlExpression> args = new List <SqlExpression>(spc.Arguments.Count);

            foreach (SqlExpression expr in spc.Arguments)
            {
                args.Add(this.VisitExpression(expr));
            }
            SqlExpression          projection = this.VisitExpression(spc.Projection);
            SqlStoredProcedureCall n          = new SqlStoredProcedureCall(spc.Function, projection, args, spc.SourceExpression);

            this.nodeMap[spc] = n;
            foreach (SqlUserColumn suc in spc.Columns)
            {
                n.Columns.Add((SqlUserColumn)this.Visit(suc));
            }
            return(n);
        }
Ejemplo n.º 7
0
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
            {
                sb.Append("EXECUTE ");
                sb.Append(spc.Function.MappedName);
                sb.Append(" ");
                int count = spc.Function.Parameters.Count;

                for (int i = 0; i < count; i++)
                {
                    MetaParameter parameter = spc.Function.Parameters[i];
                    sb.Append(parameter.MappedName);
                    if (i < count - 1)
                    {
                        sb.Append(", ");
                    }
                    parameterNames.Add(((SqlParameter)spc.Arguments[i]).Name);
                }
                return(spc);
            }
Ejemplo n.º 8
0
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc) {
                sb.Append("EXEC @RETURN_VALUE = ");
                this.WriteName(spc.Function.MappedName);
                sb.Append(" ");

                int pc = spc.Function.Parameters.Count;
                System.Diagnostics.Debug.Assert(spc.Arguments.Count >= pc);

                for (int i = 0;  i < pc; i++) {
                    MetaParameter mp = spc.Function.Parameters[i];
                    if (i > 0) sb.Append(", ");
                    this.WriteVariableName(mp.MappedName);
                    sb.Append(" = ");
                    this.Visit(spc.Arguments[i]);
                    if (mp.Parameter.IsOut || mp.Parameter.ParameterType.IsByRef)
                        sb.Append(" OUTPUT");
                }

                if (spc.Arguments.Count > pc) {
                    if (pc > 0) sb.Append(", ");
                    this.WriteVariableName(spc.Function.ReturnParameter.MappedName);
                    sb.Append(" = ");
                    this.Visit(spc.Arguments[pc]);
                    sb.Append(" OUTPUT");
                }

                return spc;
            }
Ejemplo n.º 9
0
 internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
 {
     WriteName(spc.Function.MappedName);
     return(spc);
 }
Ejemplo n.º 10
0
 internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc) {
     List<SqlExpression> args = new List<SqlExpression>(spc.Arguments.Count);
     foreach (SqlExpression expr in spc.Arguments) {
         args.Add(this.VisitExpression(expr));
     }
     SqlExpression projection = this.VisitExpression(spc.Projection);
     SqlStoredProcedureCall n = new SqlStoredProcedureCall(spc.Function, projection, args, spc.SourceExpression);
     this.nodeMap[spc] = n;
     foreach (SqlUserColumn suc in spc.Columns) {
         n.Columns.Add((SqlUserColumn)this.Visit(suc));
     }
     return n;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Translate a call to a stored procedure
        /// </summary>             
        private SqlNode TranslateStoredProcedureCall(MethodCallExpression mce, MetaFunction function) {
            if (!this.outerNode) {
                throw Error.SprocsCannotBeComposed();
            }

            // translate method call into sql function call
            List<SqlExpression> sqlParams = GetFunctionParameters(mce, function);

            SqlStoredProcedureCall spc = new SqlStoredProcedureCall(function, null, sqlParams, mce);

            Type returnType = mce.Method.ReturnType;
            if (returnType.IsGenericType &&
                (returnType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
                returnType.GetGenericTypeDefinition() == typeof(ISingleResult<>))) {

                // Since this is a single rowset returning sproc, we use the one
                // and only root metatype.
                MetaType rowType = function.ResultRowTypes[0].InheritanceRoot;
                
                SqlUserRow rowExp = new SqlUserRow(rowType, this.typeProvider.GetApplicationType((int)ConverterSpecialTypes.Row), spc, mce);
                spc.Projection = this.translator.BuildProjection(rowExp, rowType, this.allowDeferred, null, mce);
            }
            else if (!(
                typeof(IMultipleResults).IsAssignableFrom(returnType)
                || returnType == typeof(int)
                || returnType == typeof(int?)
                )) {
                throw Error.InvalidReturnFromSproc(returnType);
            }

            return spc;
        }
Ejemplo n.º 12
0
 internal virtual SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc) {
     for (int i = 0, n = spc.Arguments.Count; i < n; i++) {
         spc.Arguments[i] = this.VisitExpression(spc.Arguments[i]);
     }
     spc.Projection = this.VisitExpression(spc.Projection);
     for (int i = 0, n = spc.Columns.Count; i < n; i++) {
         spc.Columns[i] = (SqlUserColumn) this.Visit(spc.Columns[i]);
     }
     return spc;
 }
Ejemplo n.º 13
0
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc)
            {
                var returnType = spc.Function.Method.ReturnType;

                if (returnType != typeof(void))//(QueryConverter.IsValidateReturnType(returnType))
                {
                    IProviderType paramType;
                    if (returnType.IsValueType || returnType == typeof(string))
                    {
                        paramType = parameterizer.TypeProvider.From(returnType);
                    }
                    else if (returnType.IsGenericType &&
                             ((returnType.GetGenericTypeDefinition() == typeof(IEnumerable <>)) ||
                              (returnType.GetGenericTypeDefinition() == typeof(ISingleResult <>))))
                    {
                        //paramType = parameterizer.TypeProvider.From(typeof(OracleRefCursor));
                        throw new NotImplementedException();
                    }
                    else
                    {
                        try
                        {
                            paramType = parameterizer.TypeProvider.From(returnType);
                        }
                        catch (Exception)
                        {
                            throw SqlClient.Error.InvalidReturnFromSproc(returnType);
                        }
                    }
                    var parameter3 = new SqlParameter(returnType, paramType,
                                                      "@RETURN_VALUE", spc.SourceExpression)
                    {
                        Direction = ParameterDirection.Output
                    };
                    currentParams.Add(new SqlParameterInfo(parameter3));
                }

                this.VisitUserQuery(spc);

                //if (returnType != typeof(void))
                int num   = 0;
                int count = spc.Function.Parameters.Count;

                while (num < count)
                {
                    MetaParameter p    = spc.Function.Parameters[num];
                    var           node = spc.Arguments[num] as SqlParameter;
                    if (node != null)
                    {
                        if (string.Equals(p.DbType, "Cursor", System.StringComparison.CurrentCultureIgnoreCase))
                        {
                            node.Direction = ParameterDirection.Output;
                        }
                        else
                        {
                            node.Direction = GetParameterDirection(p);
                        }
                        Debug.Assert(!string.IsNullOrEmpty(p.MappedName));
                        node.Name = p.MappedName.StartsWith(":") ? p.MappedName : ":" + p.MappedName;//p.MappedName;
                        if ((node.Direction == ParameterDirection.InputOutput) ||
                            (node.Direction == ParameterDirection.Output))
                        {
                            RetypeOutParameter(node);
                        }
                    }
                    num++;
                }


                return(spc);
            }
            internal override SqlStoredProcedureCall VisitStoredProcedureCall(SqlStoredProcedureCall spc) {
                this.VisitUserQuery(spc);

                for (int i = 0, n = spc.Function.Parameters.Count; i < n; i++) {
                    MetaParameter mp = spc.Function.Parameters[i];
                    SqlParameter arg = spc.Arguments[i] as SqlParameter;
                    if (arg != null) {
                        arg.Direction = this.GetParameterDirection(mp);
                        if (arg.Direction == ParameterDirection.InputOutput ||
                            arg.Direction == ParameterDirection.Output) {
                            // Text, NText and Image parameters cannot be used as output parameters
                            // so we retype them if necessary.
                            RetypeOutParameter(arg);
                        }
                    }
                }

                // add default return value 
                SqlParameter p = new SqlParameter(typeof(int?), this.parameterizer.typeProvider.From(typeof(int)), "@RETURN_VALUE", spc.SourceExpression);
                p.Direction = System.Data.ParameterDirection.Output;
                this.currentParams.Add(new SqlParameterInfo(p));

                return spc;
            }