VenturaSQL 4 Web API

Starting with VenturaSQL version 4, the middleware is exposed as a Web API using an ASP.NET controller.

using VenturaSQL;
using VenturaSQL.AspNetCore.Server.RequestHandling;

namespace BlazorDemo.Server.Controllers
{
    [ApiController]
    [Authorize]
    public class VenturaSqlController : ControllerBase
    {
        [Route("api/venturasql")]
        [HttpPost]
        public async Task<IActionResult> Index(byte[] requestData)
        {

            var processor = new VenturaSqlServerEngine();
            processor.CallBacks.LookupAdoConnector = LookupAdoConnector;
            await processor.ExecAsync(requestData);
            Response.ContentType = "application/octet-stream";
            await Response.Body.WriteAsync(processor.ResponseBuffer, 0, processor.ResponseLength);
            return Ok();
        }

        private AdoConnector LookupAdoConnector(string requestedName)
        {
            if (requestedName == "DefaultConnector")
                return new AdoConnector(SqlClientFactory.Instance, "Server=tcp:sysdev-sqlserver-public.database.windows.net,1433;Initial Catalog=AdventureWorks2017;...");

            throw new Exception($"Requested connector name {requestedName} is unknown on server.");
        }
    }
}

In the C# code above, the requestData byte array is created by the recordsets on the client and transmitted to the server in binary format. The VenturaSqlServerEngine will perform the requested database operations and return the data to the client in binary format. The client then unpacks the data and fills the rows in the recordsets.

Leave a Reply

Your email address will not be published. Required fields are marked *