Exemplo n.º 1
0
        public async Task <object> Invoke(dynamic parameters)
        {
            try
            {
                string   connectionString = (string)parameters.dsn;
                string   commandString    = (string)parameters.query;
                string   prep             = (string)parameters.prepare;
                var      rek_data         = new List <Prep_val>();
                List_val values           = new List_val()
                {
                    Query = commandString
                };
                if (prep == "true")
                {
                    var dict = (IDictionary <string, object>)parameters.Values;
                    int i    = 1;
                    while (dict.ContainsKey("Val_name" + i))
                    {
                        int      len = dict.ContainsKey("Len" + i) ? (int)dict["Len" + i] : 1;
                        Prep_val tmp = new Prep_val
                        {
                            Value    = dict["Value" + i],
                            Val_name = (string)dict["Val_name" + i],
                            Type     = (string)dict["Type" + i],
                            Counter  = 0,
                            Len      = len
                        };
                        rek_data.Add(tmp);
                        i++;
                    }
                    values = new List_val()
                    {
                        Query  = commandString,
                        Values = rek_data
                    };
                }
                string command = commandString.Substring(0, 6).Trim().ToLower();
                switch (command)
                {
                case "select":
                    return(await this.ExecuteQuery(connectionString, values));

                case "insert":
                case "update":
                case "delete":
                    return(await this.ExecuteNonQuery(connectionString, values));

                default:
                    throw new InvalidOperationException("Unsupported type of SQL command. Only select, insert, update, delete are supported.");
                }
            }
            catch (Exception e)
            {
                throw new Exception("Parsing data error " + e, e);
            }
        }
Exemplo n.º 2
0
        private List_val Create_non_parametr(List_val prep)
        {
            List <Prep_val> rek_data = new List <Prep_val>();

            try
            {
                string quer = prep.Query;
                int    ind  = 0;
                foreach (Prep_val item in prep.Values)
                {
                    while (ind != -1)
                    {
                        ind = quer.IndexOf(item.Val_name, ind);
                        if (ind > 0)
                        {
                            Prep_val prm = new Prep_val
                            {
                                Val_name = item.Val_name,
                                Value    = item.Value,
                                Type     = item.Type,
                                Counter  = ind,
                                Len      = item.Len
                            };
                            rek_data.Add(prm);
                            ind++;
                        }
                    }
                    ind = 0;
                }
                foreach (Prep_val item in prep.Values)
                {
                    quer = quer.Replace(item.Val_name, "?");
                }
                List_val prepare = new List_val
                {
                    Values = (from m in rek_data orderby m.Counter select m).ToList(),
                    Query  = quer
                };
                return(prepare);
            }
            catch (Exception e)
            {
                throw new Exception("Transform parametrized Error ", e);
            }
        }