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);
        }