void IDBTraits.CreateStoredProcedure(Func <DbCommand> commandCreator, StoredProcedureReference procedure, StoredProcedureBody body)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        void IDBTraits.CreateStoredProcedure(Func <DbCommand> commandCreator, StoredProcedureReference procedure, StoredProcedureBody body)
        {
            string packageEnd       = string.Format("end {0};", procedure.packageName);
            string packageEndMarker = packageEnd.ToLower();
            {
                string[] package = GetPackage(commandCreator, procedure.packageName, "PACKAGE BODY");
                try
                {
                    var position = FindProcedureBodyPosition(package, procedure);
                    throw new ApplicationException(String.Format("Procedure {0} body is already declared", procedure.procedureName));
                } catch (ProcedureNotFoundException)
                {
                }
                StringBuilder packageBuilder = new StringBuilder();
                packageBuilder.AppendLine("create or replace");
                for (int i = 0; i < package.Length; i++)
                {
                    if (package[i].Trim().ToLower() == packageEndMarker)
                    {
                        if (package.Length > i + 1)
                        {
                            throw new ApplicationException("Unexpected package end");
                        }
                        break;
                    }
                    packageBuilder.Append(package[i]);
                }
                packageBuilder.Append(FormatStoredProcedure(procedure, body));
                packageBuilder.AppendLine(packageEnd);
                using (DbCommand command = commandCreator())
                {
                    command.CommandText = packageBuilder.ToString();

                    /*Console.WriteLine();
                     * Console.WriteLine("=====PACKAGE BODY=====");
                     * Console.WriteLine(command.CommandText);
                     * Console.WriteLine("=====END PACKAGE BODY=====");*/
                    command.ExecuteNonQuery();
                }
            }
            {
                string[] packageSpec = GetPackage(commandCreator, procedure.packageName, "PACKAGE");
                try
                {
                    var position = FindProcedureHeader(packageSpec, procedure);
                    throw new ApplicationException(String.Format("Procedure {0} is already declared", procedure.procedureName));
                } catch (ProcedureNotFoundException)
                {
                }
                StringBuilder packageSpecBuilder = new StringBuilder();
                packageSpecBuilder.AppendLine("create or replace");
                for (int i = 0; i < packageSpec.Length; i++)
                {
                    if (packageSpec[i].Trim().ToLower() == packageEndMarker)
                    {
                        if (packageSpec.Length > i + 1)
                        {
                            throw new ApplicationException("Unexpected package end");
                        }
                        break;
                    }
                    packageSpecBuilder.Append(packageSpec[i]);
                }
                packageSpecBuilder.Append(FormatStoredProcedureHeader(procedure));
                packageSpecBuilder.AppendLine(";");
                packageSpecBuilder.AppendLine(packageEnd);
                using (DbCommand command = commandCreator())
                {
                    command.CommandText = packageSpecBuilder.ToString();

                    /*Console.WriteLine();
                     * Console.WriteLine("=====PACKAGE SPEC=====");
                     * Console.WriteLine(command.CommandText);
                     * Console.WriteLine("=====END PACKAGE SPEC=====");*/
                    command.ExecuteNonQuery();
                }
            }
        }
Beispiel #3
0
        void IDBTraits.ReplaceStoredProcedureBody(Func <DbCommand> commandCreator, StoredProcedureReference procedure, StoredProcedureBody newBody)
        {
            string[]      package        = GetPackage(commandCreator, procedure.packageName, "PACKAGE BODY");
            var           position       = FindProcedureBodyPosition(package, procedure);
            StringBuilder packageBuilder = new StringBuilder();

            packageBuilder.AppendLine("create or replace");
            for (int i = 0; i < position.header; i++)
            {
                packageBuilder.Append(package[i]);
            }
            packageBuilder.Append(FormatStoredProcedure(procedure, newBody));
            for (int i = position.end + 1; i < package.Length; i++)
            {
                packageBuilder.AppendFormat(package[i]);
            }

            /*Console.WriteLine();
             * Console.WriteLine("===NEW PACKAGE===");
             * Console.WriteLine(packageBuilder.ToString());
             * Console.WriteLine("===END PACKAGE===");*/
            using (DbCommand command = commandCreator())
            {
                command.CommandText = packageBuilder.ToString();
                command.ExecuteNonQuery();
            }
        }
Beispiel #4
0
        private static string FormatStoredProcedure(StoredProcedureReference procedure, StoredProcedureBody body)
        {
            StringBuilder result = new StringBuilder();

            result.Append(FormatStoredProcedureHeader(procedure));
            result.AppendLine();
            result.AppendLine("is");
            if (body.declarations.Trim() != "")
            {
                result.AppendLine(body.declarations.TrimEnd().Trim('\r', '\n'));
            }
            result.AppendLine("begin");
            if (body.body.Trim() != "")
            {
                result.AppendLine(body.body.TrimEnd().Trim('\r', '\n'));
            }
            result.AppendFormat("end {0};", procedure.procedureName);
            result.AppendLine();
            return(result.ToString());
        }
Beispiel #5
0
 public void CreateStoredProcedure(StoredProcedureReference procedure, StoredProcedureBody body)
 {
     this.traits.CreateStoredProcedure(this.CreateTextCommand, procedure, body);
 }
Beispiel #6
0
 public void ReplaceStoredProcedureBody(StoredProcedureReference procedure, StoredProcedureBody newBody)
 {
     this.traits.ReplaceStoredProcedureBody(this.CreateTextCommand, procedure, newBody);
 }