예제 #1
0
        public ResultMap MapCommandResult(MySqlCommand command)
        {
            try {
                using (MySqlDataReader reader = command.ExecuteReader()) {
                    List <ResultMap> results = new List <ResultMap>();

                    //Ensures last result is selected
                    bool nextResult = true;
                    while (nextResult)
                    {
                        String[] headers = new String[reader.FieldCount];
                        Type[]   types   = new Type[reader.FieldCount];

                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            headers[i] = reader.GetName(i);
                            types[i]   = reader.GetFieldType(i);
                        }

                        ResultMap map = new ResultMap(headers, types);
                        while (reader.Read())
                        {
                            object[] values = new object[reader.FieldCount];
                            reader.GetValues(values);

                            map.AddResult(values);
                            Console.WriteLine();
                        }

                        nextResult = reader.NextResult();
                        results.Add(map);
                    }

                    //Select Last in Query
                    return(results[results.Count - 1]);
                }
            } catch (Exception e) {
                Logger.Warning("Failed to execute Query", this.exception = e);
                return(null);
            }
        }