Exemplo n.º 1
0
        public ExternalProcedure(ExternalProcedureInfo procedureInfo)
            : base(procedureInfo)
        {
            if (procedureInfo.ExternalRef == null)
                throw new ArgumentNullException("procedureInfo", "The procedure info has no external reference specified.");

            procedureInfo.ExternalRef.CheckReference(procedureInfo);
        }
        public ExternalProcedure(ExternalProcedureInfo procedureInfo)
            : base(procedureInfo)
        {
            if (procedureInfo.ExternalRef == null)
            {
                throw new ArgumentNullException("procedureInfo", "The procedure info has no external reference specified.");
            }

            procedureInfo.ExternalRef.CheckReference(procedureInfo);
        }
        protected override void ExecuteStatement(ExecutionContext context)
        {
            //if (!context.User.CanCreateInSchema(ProcedureName.ParentName))
            //	throw new SecurityException();

            if (context.DirectAccess.RoutineExists(ProcedureName)) {
                if (!ReplaceIfExists)
                    throw new StatementException(String.Format("A routine named '{0}' already exists in the database.", ProcedureName));

                context.DirectAccess.DeleteRoutine(ProcedureName);
            }

            var parameters = new RoutineParameter[0];
            if (Parameters != null)
                parameters = Parameters.ToArray();

            ExternalRef externRef;
            if (!ExternalRef.TryParse(ExternalReference, out externRef))
                throw new FormatException(String.Format("The external reference '{0}' is not valid.", ExternalReference));

            var functionInfo = new ExternalProcedureInfo(ProcedureName, parameters, externRef) {
                Owner = context.User.Name
            };

            context.DirectAccess.CreateRoutine(functionInfo);
            //context.DirectAccess.GrantOn(DbObjectType.Routine, ProcedureName, context.User.Name, Privileges.Execute, true);
        }
Exemplo n.º 4
0
        public IRoutine GetRoutine(ObjectName routineName)
        {
            IRoutine result;

            if (!routinesCache.TryGet(routineName, out result))
            {
                var t = FindEntry(routineName);
                if (t == null || t.RowCount == 0)
                {
                    return(null);
                }

                var id         = t.GetValue(0, 0);
                var schemaName = t.GetValue(0, 1).Value.ToString();
                var name       = t.GetValue(0, 2).Value.ToString();

                var fullName = new ObjectName(ObjectName.Parse(schemaName), name);

                var t2 = GetParameters(id);

                var parameters = CreateParameters(t2);

                var routineType      = t.GetValue(0, 3).Value.ToString();
                var returnTypeString = t.GetValue(0, 6).Value.ToString();
                var owner            = t.GetValue(0, 7).Value.ToString();

                RoutineInfo info;

                SqlType returnType = null;

                if (routineType == FunctionType ||
                    routineType == ExtrernalFunctionType)
                {
                    returnType = transaction.Context.ResolveType(returnTypeString);
                }

                SqlStatement body        = null;
                ExternalRef  externalRef = null;

                if (routineType == FunctionType ||
                    routineType == ProcedureType)
                {
                    var bodyBin = (SqlBinary)t.GetValue(0, 5).Value;
                    body = bodyBin.ToObject <PlSqlBlockStatement>();
                }
                else if (routineType == ExtrernalFunctionType ||
                         routineType == ExternalProcedureType)
                {
                    var location = t.GetValue(0, 4).Value.ToString();

                    if (!ExternalRef.TryParse(location, out externalRef))
                    {
                        throw new InvalidOperationException(String.Format("The location stored for function '{0}' is invalid: {1}.",
                                                                          routineName, location));
                    }
                }

                if (routineType == FunctionType)
                {
                    info = new PlSqlFunctionInfo(fullName, parameters, returnType, body);
                }
                else if (routineType == ProcedureType)
                {
                    info = new PlSqlProcedureInfo(fullName, parameters, body);
                }
                else if (routineType == ExtrernalFunctionType)
                {
                    info = new ExternalFunctionInfo(fullName, parameters, returnType, externalRef);
                }
                else if (routineType == ExternalProcedureType)
                {
                    info = new ExternalProcedureInfo(fullName, parameters, externalRef);
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Invalid routine type '{0}' found in database", routineType));
                }

                info.Owner = owner;

                if (info is PlSqlFunctionInfo)
                {
                    result = new PlSqlFunction((PlSqlFunctionInfo)info);
                }
                else if (info is PlSqlProcedureInfo)
                {
                    result = new PlSqlProcedure((PlSqlProcedureInfo)info);
                }
                else if (info is ExternalFunctionInfo)
                {
                    result = new ExternalFunction((ExternalFunctionInfo)info);
                }
                else
                {
                    result = new ExternalProcedure((ExternalProcedureInfo)info);
                }

                routinesCache.Set(fullName, result);
            }

            return(result);
        }
Exemplo n.º 5
0
        public IRoutine GetRoutine(ObjectName routineName)
        {
            IRoutine result;
            if (!routinesCache.TryGet(routineName, out result)) {
                var t = FindEntry(routineName);
                if (t == null || t.RowCount == 0)
                    return null;

                var id = t.GetValue(0, 0);
                var schemaName = t.GetValue(0, 1).Value.ToString();
                var name = t.GetValue(0, 2).Value.ToString();

                var fullName = new ObjectName(ObjectName.Parse(schemaName), name);

                var t2 = GetParameters(id);

                var parameters = CreateParameters(t2);

                var routineType = t.GetValue(0, 3).Value.ToString();
                var returnTypeString = t.GetValue(0, 6).Value.ToString();
                var owner = t.GetValue(0, 7).Value.ToString();

                RoutineInfo info;

                SqlType returnType = null;

                if (routineType == FunctionType ||
                    routineType == ExtrernalFunctionType) {
                    returnType = transaction.Context.ResolveType(returnTypeString);
                }

                SqlStatement body = null;
                ExternalRef externalRef = null;

                if (routineType == FunctionType ||
                    routineType == ProcedureType) {
                    var bodyBin = (SqlBinary) t.GetValue(0, 5).Value;
                    body = bodyBin.ToObject<PlSqlBlockStatement>();
                } else if (routineType == ExtrernalFunctionType ||
                           routineType == ExternalProcedureType) {
                    var location = t.GetValue(0, 4).Value.ToString();

                    if (!ExternalRef.TryParse(location, out externalRef))
                        throw new InvalidOperationException(String.Format("The location stored for function '{0}' is invalid: {1}.",
                            routineName, location));
                }

                if (routineType == FunctionType) {
                    info = new PlSqlFunctionInfo(fullName, parameters, returnType, body);
                } else if (routineType == ProcedureType) {
                    info = new PlSqlProcedureInfo(fullName, parameters, body);
                } else if (routineType == ExtrernalFunctionType) {
                    info = new ExternalFunctionInfo(fullName, parameters, returnType, externalRef);
                } else if (routineType == ExternalProcedureType) {
                    info = new ExternalProcedureInfo(fullName, parameters, externalRef);
                } else {
                    throw new InvalidOperationException(String.Format("Invalid routine type '{0}' found in database", routineType));
                }

                info.Owner = owner;

                if (info is PlSqlFunctionInfo) {
                    result = new PlSqlFunction((PlSqlFunctionInfo) info);
                } else if (info is PlSqlProcedureInfo) {
                    result = new PlSqlProcedure((PlSqlProcedureInfo) info);
                } else if (info is ExternalFunctionInfo) {
                    result = new ExternalFunction((ExternalFunctionInfo) info);
                } else {
                    result = new ExternalProcedure((ExternalProcedureInfo) info);
                }

                routinesCache.Set(fullName, result);
            }

            return result;
        }
Exemplo n.º 6
0
        private void CreateExternProc1(IQuery query)
        {
            var procName = ObjectName.Parse("APP.extProc");
            var args = new[] {
                new RoutineParameter("a", PrimitiveTypes.String()),
                new RoutineParameter("b", PrimitiveTypes.String(), ParameterDirection.Output)
            };

            var externRef = ExternalRef.MakeRef(typeof(TestClass), "Procedure(string, string)");
            var procInfo = new ExternalProcedureInfo(procName, args, externRef);
            query.Access().CreateObject(procInfo);
        }