protected override string MakeDropProcedureScript(MappedMethodAttribute info) { var identifier = this.MakeIdentifier(info.Schema, info.Name); var parameterSection = string.Join(", ", info.Parameters.Select(p => p.SqlType)); return(string.Format(@"drop function if exists {0}({1}) cascade;", identifier, parameterSection)); }
protected override bool ProcedureExists(MappedMethodAttribute info) { if (procedureNames == null) { var procedureColumns = GetSchemaColumnNames(OleDbSchemaGuid.Procedures); procedureNames = GetSchemaRowValues <string>(OleDbSchemaGuid.Procedures, "PROCEDURE_NAME") .Union(GetSchemaRowValues <string>(OleDbSchemaGuid.Views, "TABLE_NAME")) .ToArray(); } return(procedureNames.Contains(info.Name)); }
protected override void ModifyQuery(MappedMethodAttribute info) { if (info.CommandType == CommandType.Text && info.Parameters.Count > 0) { var q = info.Query.Trim().ToUpperInvariant(); if (!q.StartsWith("PARAMETERS")) { var p = this.MakeParameterSection(info); info.Query = string.Format("PARAMETERS {0};\n{1}", p, info.Query); } } }
protected override void ModifyQuery(MappedMethodAttribute info) { base.ModifyQuery(info); //convert a parameterized query likely written for SQL Server // or MySQL to a format useable on Postgres var parameters = info.Parameters .OrderBy(p => p.Name.Length) .Reverse(); foreach (var param in parameters) { info.Query = info.Query.Replace("@" + param.Name, ":" + param.Name); } }
protected override string MakeCreateProcedureScript(MappedMethodAttribute info) { var identifier = this.MakeIdentifier(info.Schema ?? DefaultSchemaName, info.Name); var parameterSection = this.MakeParameterSection(info); if (parameterSection.Length > 0) { parameterSection = string.Format("({0})", parameterSection); } return(string.Format( @"CREATE PROCEDURE {0} {1} AS {2}", identifier, parameterSection, info.Query)); }
protected override string MakeCreateProcedureScript(MappedMethodAttribute info) { var identifier = this.MakeIdentifier(info.Schema, info.Name); var parameterSection = this.MakeParameterSection(info); return(string.Format( @"create procedure {0} ({1}) begin {2} end//", identifier, parameterSection, info.Query)); }
protected override string MakeCreateProcedureScript(MappedMethodAttribute info) { var identifier = this.MakeIdentifier(info.Schema ?? DefaultSchemaName, info.Name); var parameterSection = this.MakeParameterSection(info); return(string.Format( @"create or replace function {0}({1}) returns {2}{3} as $$ {4} $$ language 'sql'", identifier, parameterSection, info.IsCollection ? "setof " : "", info.SqlType, info.Query)); }
protected override string MakeCreateProcedureScript(MappedMethodAttribute info) { var identifier = this.MakeIdentifier(info.Schema ?? DefaultSchemaName, info.Name); var parameterSection = this.MakeParameterSection(info); var withRecompile = info.GetAttribute <SqlServerWithRecompileAttribute>() != null; return(string.Format( @"create procedure {0} {1} {2}as begin set nocount on; {3} end", identifier, parameterSection, withRecompile ? "with recompile\r\n" : "", info.Query)); }
protected override void ModifyQuery(MappedMethodAttribute info) { if (info.EnableTransaction) { string transactionName = string.Format("TRANS{0}", Guid.NewGuid().ToString().Replace("-", "")).Substring(0, 32); string transactionBegin = string.Format("begin try\r\nbegin transaction {0};", transactionName); string transactionEnd = string.Format( @"commit transaction {0}; end try begin catch declare @msg nvarchar(4000), @lvl int, @stt int; select @msg = error_message(), @lvl = error_severity(), @stt = error_state(); rollback transaction {0}; raiserror(@msg, @lvl, @stt); end catch;", transactionName); info.Query = string.Format("{0}\r\n{1}\r\n{2}", transactionBegin, info.Query, transactionEnd); } }
protected override bool ProcedureExists(MappedMethodAttribute info) { // just assume the procedure exists, because the drop and create // procedures will take care of it. return(true); }
protected override string MakeDropProcedureScript(MappedMethodAttribute info) { return(string.Format("drop procedure {0}", this.MakeIdentifier(info.Schema, info.Name))); }
protected override bool ProcedureExists(MappedMethodAttribute info) { return(ProcedureExistsQuery(info.Schema, info.Name)); }
protected override string MakeDropProcedureScript(MappedMethodAttribute info) { throw new System.NotImplementedException(); }
protected override bool ProcedureExists(MappedMethodAttribute info) { return(info.Name.Contains("Exists")); }
protected override string MakeDropProcedureScript(MappedMethodAttribute info) { return(string.Format("drop procedure {0}", info.Name)); }
protected override string MakeCreateProcedureScript(MappedMethodAttribute info) { throw new NotImplementedException(); }
protected override bool ProcedureExists(MappedMethodAttribute info) { throw new System.NotImplementedException(); }