89 lines
3.0 KiB
C#
89 lines
3.0 KiB
C#
using ApiDatosGuadex.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Data.Common;
|
|
using bdGrupoSanchoToro.dbcontext;
|
|
using bdGrupoSanchoToro;
|
|
|
|
namespace ApiDatosGuadex.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class HomeController : Controller
|
|
{
|
|
//metodo
|
|
[HttpGet("lee")]
|
|
public IActionResult LeeSQL(string bd, string sqlh)
|
|
{
|
|
// bdGestionGuadex.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Otros, "Inicio Log",null);
|
|
Response.ContentType = "text/plain";
|
|
try
|
|
{
|
|
|
|
DbConnection? db = null;
|
|
|
|
switch (bd.ToLower())
|
|
{
|
|
case "sanchotoro":
|
|
{
|
|
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
|
break;
|
|
}
|
|
//case "guadex":
|
|
// {
|
|
// db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
|
// break;
|
|
// }
|
|
|
|
}
|
|
// string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
|
|
string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
|
|
|
|
|
|
// termiancion en CRLF
|
|
res = res.Replace("\n", "\r\n");
|
|
|
|
return Content(res, "text/plain", System.Text.Encoding.UTF8);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en LeeSQL", ex.Message, ex);
|
|
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
|
|
}
|
|
|
|
}
|
|
public IActionResult EjeSQL(string bd, string sqlh)
|
|
{
|
|
Response.ContentType = "text/plain";
|
|
try
|
|
{
|
|
DbConnection? db = null;
|
|
switch (bd.ToLower())
|
|
{
|
|
case "sanchotoro":
|
|
{
|
|
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
|
break;
|
|
}
|
|
//case "guadex":
|
|
// {
|
|
// db = bdGuadex.tscGuadex.NuevoContexto().Database.GetDbConnection();
|
|
// break;
|
|
// }
|
|
}
|
|
string res = tsUtilidades.bbdd.EjeMySqlHex(db, sqlh);
|
|
|
|
// terminacion en CRLF
|
|
res = res.Replace("\n", "\r\n");
|
|
|
|
return Content(res, "text/plain", System.Text.Encoding.UTF8);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en EjeSQL", ex.Message, ex);
|
|
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
|
|
}
|
|
}
|
|
}
|
|
}
|