Ejemplo n.º 1
0
        public async Task <object> Go(QueryContext context, ConnectionClient client, RegistryService registry)
        {
            var describe = context.Query.Split("?", StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();

            Describe describeRequest;

            if (describe.Any())
            {
                describeRequest = new Describe()
                {
                    TableName = describe[0]
                };
            }
            else
            {
                describeRequest = new Describe()
                {
                    TableName = "sqlite_master"
                };
            }

            try
            {
                var describeResponse = await client.DescribeCommandAsync(describeRequest);

                return(new DescribeResultViewModel(describeResponse, await registry.GetServices(), context.HttpContext.Request));
            }
            catch (Exception err)
            {
                return(new DescribeResultViewModel(err.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <object> Go(QueryContext context, ConnectionClient client, RegistryService registry)
        {
            var from          = context.Query.Split("from", StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim().TrimEnd(';')).ToList();
            var fromTableName = @from[1].Split(' ')[0];

            var select            = @from[0].Split("select", StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim().TrimEnd(';')).ToList();
            var columnsOrWildcard = @select[0].Trim();

            string[] columns;

            if (columnsOrWildcard == "*")
            {
                if (fromTableName.ToLower().Equals("sqlite_master"))
                {
                    columns = Describe.DescribeMasterColumns.ToArray();
                }
                else
                {
                    columns = (await client.DescribeCommandAsync(new Describe()
                    {
                        TableName = fromTableName
                    })).Results.Select(DescribeResponse.GetName).ToArray();
                }
            }
            else
            {
                columns = @select[0].Split(',', StringSplitOptions.RemoveEmptyEntries);
            }

            var q = new Network.Server.Api.Db.Model.Query()
            {
                Select     = context.Query,
                Columns    = columns.Select(x => x?.Trim()).ToList(),
                Properties = columns.Select(x => x?.Trim()).ToList()
            };

            try
            {
                var res = await client.PostQueryAsync(q);

                return(new QueryResultViewModel(res, await registry.GetServices(), context.HttpContext.Request));
            }
            catch (Exception err)
            {
                return(new QueryResultViewModel(err.Message));
            }
        }