Exemplo n.º 1
0
        public ActionResult Adhoc(AdhocModel model)
        {
            string sql            = model.Sql;
            string currentBuiltin = model.CurrentBuiltin;

            model = new AdhocModel {
                Sql = sql, Schema = schema, Builtins = builtins, CurrentBuiltin = currentBuiltin
            };

            try
            {
                if (sql.Trim().ToLower().StartsWith("select"))
                {
                    var results = new List <List <string> >();

                    var rows = ParticipantContext.Query(sql);

                    bool first = true;
                    foreach (var row in rows)
                    {
                        if (first)
                        {
                            List <string> headers = new List <string>();
                            foreach (var column in (IDictionary <string, object>)row)  // get column names
                            {
                                headers.Add(column.Key);
                            }

                            results.Add(headers);
                            first = false;
                        }

                        var values = new List <string>();
                        foreach (var column in (IDictionary <string, object>)row)  // get column values
                        {
                            string value = column.Value == null ? "" : column.Value.ToString();
                            values.Add(value);
                        }
                        results.Add(values);
                    }

                    model.Results = results;
                }
                else
                {
                    ParticipantContext.Execute(sql);
                    model.Results.Add(new List <string> {
                        "Query ran successfully."
                    });
                }
            }
            catch (Exception ex)
            {
                model.Exception = ex.ToString();
            }


            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Adhoc()
        {
            var model = new AdhocModel {
                Schema = schema, Builtins = builtins
            };

            return(View(model));
        }