public void CreateExternalFunction() { var funName = ObjectName.Parse("APP.fun1"); var parameters = new RoutineParameter[] { new RoutineParameter("a", PrimitiveTypes.Integer()), new RoutineParameter("b", PrimitiveTypes.Integer()), }; var externRef = ExternalRef.MakeRef(typeof(Test), "Function(int, int)"); AdminQuery.CreateExternFunction(funName, PrimitiveTypes.Integer(), parameters, externRef.ToString()); var exists = AdminQuery.Access().RoutineExists(funName); Assert.IsTrue(exists); var function = AdminQuery.Access().GetObject(DbObjectType.Routine, funName); Assert.IsNotNull(function); Assert.IsInstanceOf <ExternalFunction>(function); var externFunction = (ExternalFunction)function; Assert.IsNotNull(externFunction.ExternalRef); Assert.AreEqual(typeof(Test), externFunction.ExternalRef.Type); }
public void CreateExternalProcedure() { var procName = ObjectName.Parse("APP.proc1"); var parameters = new RoutineParameter[] { new RoutineParameter("a", PrimitiveTypes.Integer()), new RoutineParameter("b", PrimitiveTypes.Integer()), }; var externRef = ExternalRef.MakeRef(typeof(Test), "Procedure(int, int)"); AdminQuery.CreateExternProcedure(procName, parameters, externRef.ToString()); var exists = AdminQuery.Access().RoutineExists(procName); Assert.IsTrue(exists); var procedure = AdminQuery.Access().GetObject(DbObjectType.Routine, procName); Assert.IsNotNull(procedure); Assert.IsInstanceOf <ExternalProcedure>(procedure); var externFunction = (ExternalProcedure)procedure; Assert.IsNotNull(externFunction.ExternalRef); Assert.AreEqual(typeof(Test), externFunction.ExternalRef.Type); }
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); }
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); }
public static List <ExternalRef> GetSpdxExternalRefs(this Component component) { if (component.Properties == null) { return(null); } var extRefs = new List <ExternalRef>(); foreach (var extRefProp in component.Properties.Where(p => p.Name.StartsWith(PropertyTaxonomy.EXTERNAL_REFERENCE))) { var extRef = new ExternalRef(); if (extRefProp.Name.StartsWith(PropertyTaxonomy.EXTERNAL_REFERENCE_OTHER)) { extRef.ReferenceCategory = ExternalRefCategory.OTHER; extRef.ReferenceType = extRefProp.Name.Substring(PropertyTaxonomy.EXTERNAL_REFERENCE_OTHER.Length + 1); } else { switch (extRefProp.Name) { case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE22: extRef.ReferenceCategory = ExternalRefCategory.SECURITY; extRef.ReferenceType = "cpe22Type"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE23: extRef.ReferenceCategory = ExternalRefCategory.SECURITY; extRef.ReferenceType = "cpe23Type"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_MAVEN_CENTRAL: extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER; extRef.ReferenceType = "maven-central"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NPM: extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER; extRef.ReferenceType = "npm"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NUGET: extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER; extRef.ReferenceType = "nuget"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_BOWER: extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER; extRef.ReferenceType = "bower"; break; case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_PURL: extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER; extRef.ReferenceType = "purl"; break; //TODO add this back in once the SPDX JSON schema is fixed https://github.com/spdx/spdx-spec/issues/612 //TODO and write corresponding code in AddExternalRefsToCDX // case PropertyTaxonomy.EXTERNAL_REFERENCE_PERSISTENT_ID_SWH: // extRef.ReferenceCategory = ExternalRefCategory.PERSISTENT_ID; // extRef.ReferenceType = "swh"; // break; } } if (extRef.ReferenceType != null) { var parts = extRefProp.Value.Split(' '); extRef.ReferenceLocator = parts[0]; if (parts.Length > 1) { extRef.Comment = String.Join(" ", extRefProp.Value.Split(' ').Skip(1).ToList()); } extRefs.Add(extRef); } } return(extRefs.Count == 0 ? null : extRefs); }