Beispiel #1
0
        /// <summary>
        ///		Ejecuta un script SQL interpretándolo antes
        /// </summary>
        private void ExecuteScriptSqlParsed(ProviderModel provider, string fileName, SentenceExecuteScript sentence)
        {
            List <SqlSectionModel> sections = new SqlParser().TokenizeByFile(fileName, MapVariables(GetVariables(), sentence.Mapping), out string error);

            // Si no hay ningún error, ejecuta el script
            if (string.IsNullOrWhiteSpace(error))
            {
                // Recorre las seccionaes
                foreach (SqlSectionModel section in sections)
                {
                    if (string.IsNullOrWhiteSpace(error) && section.Type == SqlSectionModel.SectionType.Sql &&
                        !string.IsNullOrWhiteSpace(section.Content))
                    {
                        try
                        {
                            provider.Execute(CreateDataProviderCommand(section.Content, sentence.Timeout));
                        }
                        catch (Exception exception)
                        {
                            error = $"Error when execute script {System.IO.Path.GetFileName(fileName)}. {exception.Message}";
                        }
                    }
                }
            }
            // Añade el error
            if (!string.IsNullOrWhiteSpace(error))
            {
                AddError(error);
            }
        }
Beispiel #2
0
        /// <summary>
        ///		Ejecuta un script SQL (sin interpretarlo)
        /// </summary>
        private void ExecuteScriptSqlRaw(ProviderModel provider, string fileName, TimeSpan timeout, bool skipParameters)
        {
            string error = string.Empty;

            // Ejecuta el comando completo del archivo SQL
            try
            {
                string sql = LibHelper.Files.HelperFiles.LoadTextFile(fileName);

                provider.Execute(CreateDataProviderCommand(sql, timeout, skipParameters));
            }
            catch (Exception exception)
            {
                error = $"Error when execute script {System.IO.Path.GetFileName(fileName)}. {exception.Message}";
            }
            // Añade el error
            if (!string.IsNullOrWhiteSpace(error))
            {
                AddError(error);
            }
        }