コード例 #1
0
        private static void ParseCommand(ChildBuilder child)
        {
            switch (child.KeyParam)
            {
            case ParentBuilder.Statements.Select:
                if (child.OptionalParam.Contains("S"))
                {
                    child.SetCommand(Select.CreateQuery(child.Table));
                }
                else
                {
                    child.SetCommand(Select.CreateQuery(child.Table, child.ReturnValue));

                    string[] keys = child.ReturnValue.Keys.ToArray();
                }

                _command.CommandText = child.Command;
                _command.Prepare();

                var reader = _command.ExecuteReader();

                var index = 0;

                var temp = child.ReturnValue;
                //read each line returned
                while (reader.Read())
                {
                    //new dictionary to hold all of the records
                    //dictList.Add(new Dictionary<string, string>());

                    try
                    {
                        var i = 0;
                        //read each line and add it to the newest dictionary in the list
                        while (i < child.ReturnValue.Keys.Count)
                        {
                            var read = reader.GetValue(i).ToString();
                            //Console.WriteLine(read);
                            // dictList.ElementAt(index).Add(dict.Keys.ElementAt(i), read);
                            temp.Values.ElementAt(i).Add(read);

                            i++;
                        }
                    }
                    catch (Exception c)
                    {
                        Reporter.WriteContent("Exception thrown in RetriveTable: " + c, 0);
                    }

                    index++;
                }
                reader.Close();

                child.SetReturnValue(temp);

                if (child.OptionalParam.Contains("P"))
                {
                    for (int c = 0; c < child.ReturnValue.Values.ElementAt(0).Count; c++)
                    {
                        Console.WriteLine("Record " + c + ":");
                        for (int i = 0; i < child.ReturnValue.Keys.Count; i++)
                        {
                            Console.WriteLine("-" + child.ReturnValue.Keys.ElementAt(i) + ": \t" + child.ReturnValue.Values.ElementAt(i).ElementAt(c));
                        }

                        Console.WriteLine();
                    }
                }

                break;

            case ParentBuilder.Statements.Insert:

                for (int i = 0; i < child.ReturnValue.Values.ElementAt(0).Count; i++)
                {
                    Fresh();

                    _command.CommandText = Insert.CreateQuery(child.Table, child.ReturnValue);

                    PrepareCommand(child, i);

                    Execute();
                }

                Fresh();

                break;


            case ParentBuilder.Statements.Update:
                string tempCommand = Update.CreateQuery(child.Table, child.ReturnValue);

                if (!child.OptionalParam.Contains("UA"))
                {
                    try
                    {
                        List <string> optionalParam = new List <string>();
                        child.ReturnValue.TryGetValue("WHERE", out optionalParam);

                        tempCommand += "WHERE " + optionalParam.ElementAt(0);

                        _command.CommandText = tempCommand;
                    }
                    catch (Exception ex)
                    {
                        Rollback();

                        Reporter.WriteContent("Exeption thrown in DB Connection Delete: " + ex, 0);
                    }
                }



                break;

            case ParentBuilder.Statements.Delete:

                for (int i = 0; i < child.ReturnValue.Count; i++)
                {
                    Fresh();

                    _command.CommandText = Delete.CreateQuery(child.Table, child.ReturnValue.Keys.ElementAt(i), child.ReturnValue.Values.ElementAt(i).ElementAt(0));

                    Execute();
                }

                Fresh();

                break;
            }
        }