AddResult() public method

Adds a result to the list of results.
public AddResult ( object rawValues ) : void
rawValues object the array of raw values
return void
 public void Sort_TwoFieldsAscending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     resultSet.AddField("Age");
     resultSet.AddResult(new object[] { "Bob", 21 });
     resultSet.AddResult(new object[] { "Bob", 19 });
     resultSet.AddResult(new object[] { "Peter", 40 });
     resultSet.AddResult(new object[] { "Peter", 30 });
     var orderCriteria = OrderCriteria.FromString("Name, Age");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual("Bob", rows[0].Values[0]);
     Assert.AreEqual(19, rows[0].Values[1]);
     Assert.AreEqual("Bob", rows[1].Values[0]);
     Assert.AreEqual(21, rows[1].Values[1]);
     Assert.AreEqual("Peter", rows[2].Values[0]);
     Assert.AreEqual(30, rows[2].Values[1]);
     Assert.AreEqual("Peter", rows[3].Values[0]);
     Assert.AreEqual(40, rows[3].Values[1]);
 }
 public void Sort_OneFieldDescending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     resultSet.AddResult(new object[] { "aaaaa" });
     resultSet.AddResult(new object[] { "zzzzz" });
     var orderCriteria = OrderCriteria.FromString("Name DESC");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual("zzzzz", rows[0].Values[0]);
     Assert.AreEqual("aaaaa", rows[1].Values[0]);
 }
        /// <summary>
        /// Populates a <see cref="QueryResult"/> using the given <see cref="ISelectQuery"/>.
        /// With this method you can execute a custom select query and get a result set back. If you are loading against a
        /// database, the <see cref="IClassDef"/> associated to the <see cref="ISelectQuery"/> will be used to map property names 
        /// to database fields and will also be used to convert values that are returned from the database to the expected
        /// type. This can be used to get result sets that span tables.  
        /// </summary>
        /// <param name="selectQuery">The select query to execute</param>
        /// <returns>A <see cref="QueryResult"/> that contains the results of the query</returns>
        public IQueryResult GetResultSet(ISelectQuery selectQuery)
        {
            var classDef = selectQuery.ClassDef;
            var criteria = selectQuery.Criteria;
            QueryBuilder.PrepareCriteria(classDef, criteria);
            //Ensure that all the criteria field sources are merged correctly
            selectQuery.Criteria = criteria;
            selectQuery.Fields.ForEach(pair =>
            {
                var field = pair.Value;
                var fieldSource = field.Source;
                QueryBuilder.PrepareField(fieldSource, classDef, field);
                selectQuery.Source.MergeWith(field.Source);
                field.Source = field.Source.ChildSourceLeaf;
            });
            var queryDb = new SelectQueryDB(selectQuery, _databaseConnection);
            var statement = queryDb.CreateSqlStatement();
            var resultSet = new QueryResult();
            var propNames = selectQuery.Fields.Keys;
            propNames.ForEach(resultSet.AddField);

            using (IDataReader dr = _databaseConnection.LoadDataReader(statement))
            {
                while (dr.Read())
                {
                    var rawValues = new object[dr.FieldCount];
                    dr.GetValues(rawValues);
                    resultSet.AddResult(rawValues);
                }
            }
            return resultSet;
        }
 public void Sort_OneFieldAscending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     const string lastValue = "zzzzz";
     const string firstValue = "aaaaa";
     resultSet.AddResult(new object[] { lastValue });
     resultSet.AddResult(new object[] { firstValue });
     var orderCriteria = new OrderCriteria();
     orderCriteria.Add("Name");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(firstValue, rows[0].Values[0]);
     Assert.AreEqual(lastValue, rows[1].Values[0]);
 }
Example #5
0
 public void AddResult_ShouldAddRowToRowsList()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     var name = TestUtil.GetRandomString();
     //---------------Execute Test ----------------------
     resultSet.AddResult(new object[] {name});
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(1, rows.Count);
     Assert.AreEqual(name, rows[0].RawValues[0]);
 }
        /// <summary>
        /// Populates a <see cref="QueryResult"/> using the given <see cref="ISelectQuery"/>.
        /// With this method you can execute a custom select query and get a result set back. If you are loading against a
        /// database, the <see cref="IClassDef"/> associated to the <see cref="ISelectQuery"/> will be used to map property names 
        /// to database fields and will also be used to convert values that are returned from the database to the expected
        /// type. This can be used to get result sets that span tables.  
        /// </summary>
        /// <param name="selectQuery">The select query to execute</param>
        /// <returns>A <see cref="QueryResult"/> that contains the results of the query</returns>
        public IQueryResult GetResultSet(ISelectQuery selectQuery)
        {
            QueryBuilder.PrepareCriteria(selectQuery.ClassDef, selectQuery.Criteria);
            var collection = _dataStore.FindAll(selectQuery.ClassDef, selectQuery.Criteria);
            var resultSet = new QueryResult();
            var propNames = selectQuery.Fields.Keys;
            propNames.ForEach(resultSet.AddField);

            foreach (IBusinessObject bo in collection)
            {
                var bo1 = bo;
                resultSet.AddResult(
                    propNames.Select(s => new BOMapper(bo1).GetPropertyValueToDisplay(s))
                        .ToArray()
                    );
            }
            var sorter = new QueryResultSorter();
            sorter.Sort(resultSet, selectQuery.OrderCriteria);
            return resultSet;
        }