public IActionResult TestQuery([FromBody] TReportsTestQueryRequest request) { Log.Information("***Executando método 'TestQuery'***"); Log.Information("-----Leitura dos parâmetros -----" + System.Environment.NewLine); Log.Information(JsonConvert.SerializeObject(request)); Log.Information(System.Environment.NewLine); Log.Information("-----Fim da leitura dos parâmetros -----" + System.Environment.NewLine); try { GetDataSql(GetSentenceSql(request.SqlText, request.SqlParameters), out IEnumerable <Column> columns); return(Ok(new TReportsTestSuccessResponse())); } catch (Exception ex) { Log.Error(ex.Message); Response.StatusCode = 500; return(Accepted(new TReportsCustomError() { code = "500", detailedMessage = ex.StackTrace, message = ex.Message })); } }
public async Task <IActionResult> TestQuery([FromBody] TReportsTestQueryRequest request) { return(await base.TestQuery(request)); }
/// <summary> /// Faz o teste de uma query /// </summary> /// <param name="request"></param> /// <returns></returns> protected async Task <IActionResult> TestQuery([FromBody] TReportsTestQueryRequest request) { Log.Information("***Executando método 'TestQuery'***"); Log.Information("-----Leitura dos parâmetros -----" + System.Environment.NewLine); Log.Information(JsonConvert.SerializeObject(request)); Log.Information(System.Environment.NewLine); Log.Information("-----Fim da leitura dos parâmetros -----" + System.Environment.NewLine); try { string sql = request.SqlText; if (sql.ToUpper().Contains("WHERE")) { sql = sql.Substring(sql.IndexOf("WHERE", StringComparison.InvariantCultureIgnoreCase) + 5); } else { sql = "1=1"; } if (request.SqlParameters != null) { foreach (SqlParameter parameter in request.SqlParameters) { string parAux = parameter.ParamType == "System.String" || parameter.ParamType == "System.DateTime" ? "'{0}'" : "{0}"; sql = sql.Replace($":{parameter.ParamName}", string.Format(parAux, parameter.ParamValue)); } } DataTable tableEmpresa = new DataTable(); tableEmpresa.ReadXml("Data\\Empresa.xml"); try { tableEmpresa.Select(sql); return(Ok(new TReportsTestSuccessResponse())); } catch { } DataTable tableFilial = new DataTable(); tableFilial.ReadXml("Data\\Filial.xml"); try { tableEmpresa.Select(sql); return(Ok(new TReportsTestSuccessResponse())); } catch { throw; } } catch (Exception ex) { Log.Error(ex.Message); Response.StatusCode = 500; return(Accepted(new TReportsCustomError() { code = "500", detailedMessage = ex.StackTrace, message = ex.Message })); } }