Exemplo n.º 1
0
        private static void WriteProcedure(DatabaseStoredProcedure procedure, ProcedureWriter procWriter)
        {
            foreach (var argument in procedure.Arguments)
            {
                if (argument.Out)
                {
                    //we don't deal with INOUT parameters.
                    procWriter.AddOutputParameter(argument.Name, argument.DatabaseDataType);
                    continue;
                }
                //an IN sproc
                procWriter.AddParameter(argument.Name, argument.DatabaseDataType);
            }
            procWriter.BeginProcedure();

            var sql = procedure.Sql.Trim()
                      //standardize to windows line endings
                      .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");

            //remove the BEGIN and END as the procWriter writes these
            if (sql.StartsWith("BEGIN", StringComparison.OrdinalIgnoreCase))
            {
                sql = sql.Substring(5);
            }
            if (sql.EndsWith("END", StringComparison.OrdinalIgnoreCase))
            {
                sql = sql.Substring(0, sql.Length - 3).Trim();
            }

            procWriter.AddSql(sql);
        }
Exemplo n.º 2
0
        public override string AddProcedure(DatabaseStoredProcedure procedure)
        {
            if (string.IsNullOrEmpty(procedure.Sql))
            {
                //the procedure.Sql contains the BEGIN to END statements, not the CREATE PROCEDURE and arguments.
                //for now, just comment
                return("-- add procedure " + procedure.Name);
            }

            var name       = procedure.Name;
            var procWriter = new ProcedureWriter(name, null);

            WriteProcedure(procedure, procWriter);

            return(procWriter.End());
        }
Exemplo n.º 3
0
        public override string AddFunction(DatabaseFunction databaseFunction)
        {
            if (string.IsNullOrEmpty(databaseFunction.Sql))
            {
                //the function.Sql contains the BEGIN to END statements, not the CREATE FUNCTION and arguments.
                //for now, just comment
                return("-- add function " + databaseFunction.Name);
            }

            var name       = databaseFunction.Name;
            var procWriter = new ProcedureWriter(name, true);

            procWriter.AddReturns(databaseFunction.ReturnType);
            WriteProcedure(databaseFunction, procWriter);

            return(procWriter.End());
        }