private IDbCommandResult QueryResultOfDictionary(IEnumerable<IDictionary> dictionaries)
        {
            var result = new QueryResult();

            var columnNames = new HashSet<object>();
            foreach (var dictionary in dictionaries)
            {
                foreach (var key in dictionary.Keys)
                {
                    columnNames.Add(key.ToString());
                }
            }

            foreach (var columnName in columnNames)
            {
                result.AddColumn(columnName.ToString(), typeof(string));
            }
            foreach (var dictionary in dictionaries)
            {
                var values = new List<string>();
                foreach (var columnName in columnNames)
                {
                    if (dictionary.Contains(columnName))
                    {
                        values.Add(dictionary[columnName].ToString());
                    }
                    else
                    {
                        values.Add(string.Empty);
                    }
                }
            }
            return result;
        }
示例#2
0
        public IDbCommandResult Execute(string command)
        {
            try
            {
                _dbConnection.Open();
                var query = new SchemaQuery(command);
                var schema = GetSchemaFrom(query);
                var result = new QueryResult();

                foreach (DataColumn column in schema.Columns)
                {
                    if (query.SelectAll || query.ColumnNames.Contains(column.ColumnName.ToLowerInvariant()))
                    {
                        result.AddColumn(column.ColumnName, column.DataType);
                    }
                }
                foreach (DataRow row in schema.Rows)
                {
                    result.AddRow(row.ItemArray);
                }
                return result;
            }
            finally
            {
                _dbConnection.Close();
            }
        }
 public void Show(QueryResult queryResult)
 {
     foreach (var column in queryResult.Columns)
     {
         Columns.Add(new CustomBoundColumn(column));
     }
     Records.AddRange(queryResult.Rows);
     ResultText = string.Format("Rowcount: {0:0,0}", queryResult.Rowcount);
 }
示例#4
0
 private static QueryResult CreateResult(IDataRecord reader)
 {
     var result = new QueryResult();
     for (var ii = 0; ii < reader.FieldCount; ii++)
     {
         var name = reader.GetName(ii);
         var type = reader.GetFieldType(ii);
         result.AddColumn(name, type);
     }
     return result;
 }
        private IDbCommandResult QueryResultOfDynamicDataRow(IEnumerable<DynamicDataRow> values)
        {
            var result = new QueryResult();
            if (values.IsEmpty())
            {
                return result;
            }

            var columns = values.First().Columns;
            columns.Each(c => result.AddColumn(c, typeof(string)));
            foreach (var record in values)
            {
                var theRecord = record;
                result.AddRow(columns.Select(c => theRecord[c]));
            }
            return result;
        }
 private IDbCommandResult QueryResultOfValues(IEnumerable values, Type type)
 {
     var result = new QueryResult();
     result.AddColumn(type.Name, type);
     foreach (var value in values)
     {
         result.AddRow(value.AsArray());
     }
     return result;
 }
 private IDbCommandResult QueryResultOfType(IEnumerable values, Type type)
 {
     var result = new QueryResult();
     var properties = type.GetProperties();
     if (properties.IsEmpty())
     {
         return QueryResultOfValues(values, type);
     }
     foreach (var property in properties)
     {
         result.AddColumn(property.Name, property.PropertyType);
     }
     foreach (var value in values)
     {
         var theValue = value;
         var memberValues = properties.Select(p => p.GetValue(theValue, new object[0]));
         result.AddRow(memberValues);
     }
     return result;
 }