public DMSqlProcedure(SqlProcedureAttribute sql) { if (sql.Name != string.Empty) { _name = sql.Name; } }
public static string CreateProcedure_CommandText(MethodInfo method, string schema, IDictionary <string, string> map) { StringBuilder sb = new StringBuilder(); SqlProcedureAttribute procedureAttr = method.GetCustomAttribute <SqlProcedureAttribute>(); if (procedureAttr == null) { throw new InvalidOperationException(string.Format("Method '{0}' is not sql clr procedure.", method.Name)); } string name = procedureAttr.Name ?? method.Name; sb.AppendFormat(@" CREATE PROCEDURE "); if (schema != null) { sb.AppendFormat(@"[{0}].[{1}]", schema, name); } else { sb.AppendFormat(@"[{0}]", name); } sb.AppendFormat(@"({0})", string.Join(", ", method.GetParameters().Select(pi => GetSqlParameterArgument_Text(pi, map)))); sb.AppendFormat(@" AS EXTERNAL NAME [{0}].[{1}].[{2}]; GO", method.DeclaringType.Assembly.GetName().Name, method.DeclaringType.FullName, method.Name); return(sb.ToString()); }
private static TSqlCreateProcedureStatement CreateProcedure( SqlAssemblyInfo assemblyInfo, MethodInfo method, SqlProcedureAttribute info) { return(new TSqlCreateProcedureStatement( name: TSqlObjectIdentifier.Create("foundry", method.Name), parameters: method.GetParameters() .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)), definition: new TSqlClrMethodSpecifier( assemblyInfo.Name, method.DeclaringType.FullName, method.Name ) )); }
public static string DropProcedure_CommandText(MethodInfo method, string schema) { StringBuilder sb = new StringBuilder(); SqlProcedureAttribute procedureAttr = method.GetCustomAttribute <SqlProcedureAttribute>(); if (procedureAttr == null) { throw new InvalidOperationException(string.Format("Method '{0}' is not sql clr procedure.", method.Name)); } string name = procedureAttr.Name ?? method.Name; sb.AppendFormat(@" IF EXISTS ( SELECT * FROM sys.objects WHERE [name] = N'{0}' AND [type] = 'PC'", name); if (schema != null) { sb.AppendFormat(@" AND EXISTS ( SELECT * FROM sys.schemas WHERE sys.objects.schema_id = sys.schemas.schema_id AND sys.schemas.name = N'{0}')", schema); } sb.Append(@") DROP PROCEDURE "); if (schema != null) { sb.AppendFormat(@"[{0}].[{1}]", schema, name); } else { sb.AppendFormat(@"[{0}]", name); } sb.Append(@"; GO"); return(sb.ToString()); }
public InstallerScriptableSqlProcedure(string name, string schemaName, InstallerScriptableSqlAssembly sqlSqlAssembly, MethodInfo method) : base(name, schemaName, sqlSqlAssembly, method.DeclaringType, method) { _exportedProcedureAttribute = method.GetCustomAttribute <SqlInstallerScriptGeneratorExportedProcedure>(); _sqlProcedureAttribute = method.GetCustomAttribute <SqlProcedureAttribute>(); }
public ProcedureWrapper(SqlProcedureAttribute procdef, MethodInfo functionsygnature, string schema) : base(functionsygnature, schema) { _procdef = procdef; }
public ArrayList GetCreateString(string assemblyPath, string AssemblyName, bool IsInfer, ArrayList alMeths) { string parameters = ""; string retType; string[] retString = null; string stringName; ArrayList al = new ArrayList(); //Type attr = typeof(IDeployMethods); Assembly a = Assembly.LoadFile(assemblyPath); Type aggAttr = typeof(SqlUserDefinedAggregateAttribute); foreach (Type asmType in a.GetTypes()) { string aggName = ""; //check for aggregates if (asmType.IsDefined(aggAttr, false)) { object[] attrs = asmType.GetCustomAttributes(aggAttr, false); SqlUserDefinedAggregateAttribute agg = (SqlUserDefinedAggregateAttribute)attrs[0]; //string typeName = udt.Name; if (agg.Name != string.Empty && agg.Name != null) { aggName = agg.Name; } else { aggName = asmType.Name; } aggName = Utility.GetSysName(aggName, out stringName); if (alterAsm && CheckMethodExists(asmType.Name, aggName, alMeths)) { continue; } string dropString = "if exists(select * from sys.objects where name = '{0}')\nDROP AGGREGATE {1}"; dropString = string.Format(dropString, stringName, aggName); string createString = GetAggregate(asmType, aggName, AssemblyName); al.Add(dropString); al.Add(createString); } foreach (MethodInfo m in asmType.GetMethods(BindingFlags.Static | BindingFlags.Public)) { string realName = m.Name; string aliasName = m.Name; string sysName = ""; bool addString = false; //get the parameters parameters = ReflectParameters(m, out retType); //get custom attributes for the method object[] attr = m.GetCustomAttributes(false); if (attr.Length > 0) { for (int i = 0; i < attr.Length; i++) { addString = false; Type t = attr[i].GetType(); if (t == typeof(SqlProcedureAttribute)) { SqlProcedureAttribute sql = (SqlProcedureAttribute)attr[i]; if (sql.Name != string.Empty && sql.Name != null) { sysName = GetSysName(sql.Name, out aliasName); } DMSqlProcedure id = new DMSqlProcedure(sql); retString = id.GetCreateString(false, m, AssemblyName, parameters); addString = true; } if (t == typeof(SqlFunctionAttribute)) { SqlFunctionAttribute sql = (SqlFunctionAttribute)attr[i]; if (sql.Name != string.Empty && sql.Name != null) { sysName = GetSysName(sql.Name, out aliasName); } DMSqlFunction id = new DMSqlFunction(sql); retString = id.GetCreateString(false, m, AssemblyName, parameters, retType); addString = true; } if (t == typeof(SqlTriggerAttribute)) { SqlTriggerAttribute sql = (SqlTriggerAttribute)attr[i]; if (sql.Name != string.Empty && sql.Name != null) { sysName = GetSysName(sql.Name, out aliasName); } DMSqlTrigger id = new DMSqlTrigger(sql); retString = id.GetCreateString(false, m, AssemblyName); addString = true; } if (alterAsm && CheckMethodExists(realName, aliasName, alMeths)) { break; } if (addString) { foreach (String s in retString) { al.Add(s); } } } } else if (IsInfer) { //Debugger.Launch(); if (retType == "Void") { DMSqlProcedure id = new DMSqlProcedure(); retString = id.GetCreateString(true, m, AssemblyName, parameters); foreach (String s in retString) { al.Add(s); } } if (retType != "Void") { DMSqlFunction id = new DMSqlFunction(); retString = id.GetCreateString(true, m, AssemblyName, parameters, retType); foreach (String s in retString) { al.Add(s); } } } } } return(al); }