/// <summary> /// Ejecuta una sentencia SQL /// </summary> private async Task ExecuteSqlAsync(SentenceSql sentence, CancellationToken cancellationToken) { try { (bool executed, List <string> errors) = await Interpreter.DbScriptExecutor.ExecuteAsync(sentence.Command, GetParameters(Context.Actual.GetVariablesRecursive()), cancellationToken); // Procesa los errores if (errors.Count > 0) { string total = string.Empty; // Añade todos los errores al total foreach (string error in errors) { total += error + Environment.NewLine; } // Añade el error al procesador AddError(total); } } catch (Exception exception) { AddError($"Error when execute sql command: {sentence.Command}", exception); } }
/// <summary> /// Transforma una sentencia SQL /// </summary> private void TransformSql(SentenceSql sentence) { List <SqlSectionModel> sqlSections = GetSections(sentence.Command); // Añade las sentencias SQL (se le añade un salto de línea al contenido para que no dé errores de "out of range" al recorrer la cadena) //TODO: Corregir TransformSqlCommand para que no sea necesaro el Environment.NewLine foreach (SqlSectionModel sqlSection in sqlSections) { if (sqlSection.Type == SqlSectionModel.SectionType.Sql && !string.IsNullOrWhiteSpace(sqlSection.Content)) { AddSentence("sqlContext.sql(" + TransformSqlCommand(sqlSection.Content + Environment.NewLine, "$") + ")"); } } }