private static TSqlCreateFunctionStatement CreateTableValuedFunction( SqlAssemblyInfo assemblyInfo, MethodInfo method, SqlFunctionAttribute info) { var fillMethod = method.DeclaringType.GetMethod(info.FillRowMethodName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); return(new TSqlCreateFunctionStatement( name: TSqlObjectIdentifier.Create("foundry", method.Name), parameters: method.GetParameters() .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)), returns: new TSqlClrTableType( fillMethod.GetParameters() .Skip(1) .Select(parameter => new TSqlClrTableTypeColumn(parameter.Name, parameter.ParameterType.GetElementType())) ), definition: new TSqlClrMethodSpecifier( assemblyInfo.Name, method.DeclaringType.FullName, method.Name ) )); }
private static TSqlCreateFunctionStatement CreateFunction( SqlAssemblyInfo assemblyInfo, MethodInfo method, SqlFunctionAttribute info) { if (method.ReturnType == typeof(IEnumerable) && !(info.FillRowMethodName is null)) { return(CreateTableValuedFunction(assemblyInfo, method, info)); } return(new TSqlCreateFunctionStatement( name: TSqlObjectIdentifier.Create("foundry", method.Name), parameters: method.GetParameters() .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)), returns: TSqlType.CreateFromType(method.ReturnType), definition: new TSqlClrMethodSpecifier( assemblyInfo.Name, method.DeclaringType.FullName, method.Name ) )); }
private static void InstallMethod(SqlConnection connection, SqlAssemblyInfo assemblyInfo, MethodInfo method) { bool installed = false; var functionInfo = method.GetCustomAttribute <SqlFunctionAttribute>(); if (functionInfo != null) { var function = CreateFunction(assemblyInfo, method, functionInfo); if (CreateObject(connection, function.FunctionName, function)) { installed = true; } } var procedureInfo = method.GetCustomAttribute <SqlProcedureAttribute>(); if (procedureInfo != null) { var procedure = CreateProcedure(assemblyInfo, method, procedureInfo); if (CreateObject(connection, procedure.ProcedureName, procedure)) { installed = true; } } if (!installed) { // TODO: logging } }
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 ) )); }
private static void InstallMethods(SqlConnection connection, Assembly assembly, SqlAssemblyInfo assemblyInfo) { var methods = GetInstallableMethods(assembly); foreach (var method in methods) { InstallMethod(connection, assemblyInfo, method); } }
public static void DropAssembly(this SqlConnection connection, SqlAssemblyInfo assembly) { connection.ExecuteNonQuery($@"DROP ASSEMBLY {assembly.Name.ToSqlIdentifier()}"); }