Beispiel #1
0
        /// <summary>
        ///		Ejecuta un script de SQL
        /// </summary>
        internal async Task ExecuteAsync(IDbProvider dbProvider, string query, ArgumentListModel arguments, TimeSpan timeout, CancellationToken cancellationToken)
        {
            using (BlockLogModel block = Manager.Logger.Default.CreateBlock(LogModel.LogType.Info, "Start script execution"))
            {
                SqlScriptExecutor    executor    = new SqlScriptExecutor(Manager, dbProvider, arguments, timeout);
                DbScriptsInterpreter interpreter = new DbScriptsInterpreter(executor, Manager.Logger);

                // Ejecuta el archivo
                await interpreter.ExecuteAsync(query, null, cancellationToken);

                // Recopila los errores
                Errors.AddRange(interpreter.Errors);
                // y los pasa al log
                if (Errors.Count == 0)
                {
                    block.Info("End script execution");
                }
                else
                {
                    string error = string.Empty;

                    // Agrega los errores
                    foreach (string inner in Errors)
                    {
                        error += inner + Environment.NewLine;
                    }
                    // log
                    block.Error($"Error when execute sql script: {Environment.NewLine}{error}");
                }
            }
        }
        /// <summary>
        ///		Interpreta un archivo
        /// </summary>
        private ProgramModel Parse(string fileName)
        {
            ProgramModel program = new DbScriptsInterpreter(null, Exporter.Logger).Parse(LibHelper.Files.HelperFiles.LoadTextFile(Source));

            if (program.Errors.Count > 0)
            {
                throw new ArgumentException($"Cant compile {fileName}");
            }
            else
            {
                return(program);
            }
        }
Beispiel #3
0
        public void Parse_files(string sourceFile, string targetFile, bool hasError)
        {
            Processors.DbScriptFakeExecutor executor    = new Processors.DbScriptFakeExecutor();
            DbScriptsInterpreter            interpreter = new DbScriptsInterpreter(executor, new Bau.Libraries.LibLogger.Core.LogManager());
            ProgramResultModelCollection    results     = LoadResults(targetFile);
            bool executed;

            // Ejecuta el archivo
            executed = interpreter.Execute(LoadFile(sourceFile), null);
            // Comprueba si ha habido algún error
            Assert.Equal(hasError, !executed);
            // Comprueba los resultados
            if (executed)
            {
                CheckResults(executor.Results, results);
            }
        }
Beispiel #4
0
 public DbScriptsProcessor(DbScriptsInterpreter interpreter) : base(new LibInterpreter.Interpreter.ProcessorOptions())
 {
     Interpreter = interpreter;
 }