Exemplo n.º 1
0
        public void EditNiceNames(ResultColumns coll)
        {
            DataTable         dt   = ProLogForNiceNames(coll);
            DataRowCollection rows = dt.Rows;

            foreach (ResultColumn o in coll)
            {
                rows.Add(new object[] { o.Name, o.Alias, o });
            }

            EpilogForNiceNames(dt);
        }
Exemplo n.º 2
0
 private static string DisplayResultSuiteToString(ResultSuite suite, ResultColumns columns, BenchmarkResult standardForScore)
 {
     using (MemoryStream stream = new MemoryStream())
     using (StreamWriter writer = new StreamWriter(stream))
     using (StreamReader reader = new StreamReader(stream))
     {
         suite.Display(writer, columns, standardForScore);
         writer.Flush();
         stream.Position = 0;
         return reader.ReadToEnd();
     }
 }
Exemplo n.º 3
0
 private static string DisplayResultSuiteToString(ResultSuite suite, ResultColumns columns, BenchmarkResult standardForScore)
 {
     using (MemoryStream stream = new MemoryStream())
         using (StreamWriter writer = new StreamWriter(stream))
             using (StreamReader reader = new StreamReader(stream))
             {
                 suite.Display(writer, columns, standardForScore);
                 writer.Flush();
                 stream.Position = 0;
                 return(reader.ReadToEnd());
             }
 }
Exemplo n.º 4
0
 internal SingleQuery(QuantifierType quantifier
                      , bool hasTop
                      , int top
                      , bool hasWildcard
                      , ResultColumns results
                      , IFromSource from
                      , Predicate where
                      , GroupBy groupBy
                      , Predicate having
                      , OrderBy orderBy
                      , ILimitClause limit
                      , Comments comments)
     : base(quantifier, hasTop, top, hasWildcard, results, from, where, groupBy, having, comments)
 {
     this.OrderBy = orderBy;
     this.Limit   = limit;
     //this.IsSubQuery = true;
 }
Exemplo n.º 5
0
        public void EditNiceNames(ResultColumns coll)
        {
            if (this._currentHashCode == coll.GetHashCode())
            {
                return;
            }

            DataTable         dt   = ProLogForNiceNames(coll);
            DataRowCollection rows = dt.Rows;

            foreach (ResultColumn o in coll)
            {
                rows.Add(new object[] { o.Name, o.Alias, o });
            }

            EpilogForNiceNames(dt);

            this._currentHashCode = coll.GetHashCode();
        }
        public override void AppendTo(StringBuilder sb, ISqlDialect dialect)
        {
            if (ResultColumns == null)
            {
                throw new ArgumentNullException("ResultColumns");
            }

            sb.Append("SELECT ");
            sb.Append(ResultColumns.ToString());

            if (Source != null)
            {
                sb.Append(" FROM ");
                Source.AppendTo(sb, dialect);
            }

            foreach (var joinCommand in JoinClauses)
            {
                sb.Append(" ");
                joinCommand.AppendTo(sb);
            }

            if (WhereClause != null)
            {
                sb.Append(" ");
                WhereClause.AppendTo(sb);
            }
            if (GroupByClause != null)
            {
                sb.Append(" ");
                GroupByClause.AppendTo(sb);
            }
            if (OrderByClause != null)
            {
                sb.Append(" ");
                OrderByClause.AppendTo(sb);
            }
            if (LimitClause != null)
            {
                sb.Append(" ");
                LimitClause.AppendTo(sb);
            }
        }
Exemplo n.º 7
0
        // Adds a result column binding from a column name (from the result set for the function) to
        // a propagator result (which contains the context necessary to back-propagate the result).
        // If the result is an identifier, binds the
        internal void AddResultColumn(UpdateTranslator translator, String columnName, PropagatorResult result)
        {
            const int initializeSize = 2; // expect on average less than two result columns per command

            if (null == ResultColumns)
            {
                ResultColumns = new List <KeyValuePair <string, PropagatorResult> >(initializeSize);
            }
            ResultColumns.Add(new KeyValuePair <string, PropagatorResult>(columnName, result));

            var identifier = result.Identifier;

            if (PropagatorResult.NullIdentifier != identifier)
            {
                if (translator.KeyManager.HasPrincipals(identifier))
                {
                    throw new InvalidOperationException(Strings.Update_GeneratedDependent(columnName));
                }

                // register output identifier to enable fix-up and dependency tracking
                AddOutputIdentifier(columnName, identifier);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Displays the results, optionally scaling scores to the given standard, printing to the given TextWriter.
        /// </summary>
        /// <param name="output">TextWriter to output to</param>
        /// <param name="columns">Columns to display</param>
        /// <param name="standardForScore">Result to count as a score of 1.0. May be null, in which
        /// case the raw scores (ticks per iteration) are displayed.</param>
        public void Display(TextWriter output, ResultColumns columns, BenchmarkResult standardForScore)
        {
            output.WriteLine("============ {0} ============", name);

            List <List <string> > formattedColumns = new List <List <string> >();

            // This isn't as easy to do in a query expression as one might expect.
            foreach (ResultColumns candidateColumn in IndividualColumns)
            {
                if ((columns & candidateColumn) != 0)
                {
                    Func <BenchmarkResult, BenchmarkResult, string> formatter = Formatters[candidateColumn];
                    formattedColumns.Add(this.Select(result => formatter(result, standardForScore)).ToList());
                }
            }
            List <int> maxLengths = formattedColumns.Select(col => col.Max(entry => entry.Length)).ToList();

            for (int row = 0; row < results.Count; row++)
            {
                for (int col = 0; col < formattedColumns.Count; col++)
                {
                    string unpadded = formattedColumns[col][row];
                    if (col == 0)
                    {
                        output.Write(unpadded.PadRight(maxLengths[col]));
                    }
                    else
                    {
                        output.Write(" ");
                        output.Write(unpadded.PadLeft(maxLengths[col]));
                    }
                }
                output.WriteLine();
            }
            output.WriteLine();
        }
Exemplo n.º 9
0
        public void TestAll()
        {
            ResultColumns knownColumns = ResultColumns.Name | ResultColumns.Duration | ResultColumns.Iterations | ResultColumns.Score;

            Assert.AreEqual(ResultColumns.All & knownColumns, knownColumns);
        }
 void IVisitor.VisitBefore(ResultColumns resultColumns)
 {
     this.ParentExists(resultColumns);
 }
 void IVisitor.VisitAfter(ResultColumns resultColumns)
 {
     this.ParentExists(resultColumns);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Displays the results, optionally scaling scores to the given standard, printing to Console.Out.
 /// </summary>
 /// <param name="columns">Columns to display</param>
 /// <param name="standardForScore">Result to count as a score of 1.0. May be null, in which
 /// case the raw scores (ticks per iteration) are displayed.</param>
 public void Display(ResultColumns columns, BenchmarkResult standardForScore)
 {
     Display(Console.Out, columns, standardForScore);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Convenience method to display the results when no score scaling is required and output should be Console.Out.
 /// </summary>
 /// <param name="columns"></param>
 public void Display(ResultColumns columns)
 {
     Display(columns, null);
 }
Exemplo n.º 14
0
        /// <summary>
        ///     See comments in <see cref="UpdateCommand" />.
        /// </summary>
        internal override async Task <long> ExecuteAsync(
            Dictionary <int, object> identifierValues,
            List <KeyValuePair <PropagatorResult, object> > generatedValues, CancellationToken cancellationToken)
        {
            var connection = Translator.Connection;

            // configure command to use the connection and transaction for this session
            _dbCommand.Transaction = ((null == connection.CurrentTransaction)
                                          ? null
                                          : connection.CurrentTransaction.StoreTransaction);
            _dbCommand.Connection = connection.StoreConnection;
            if (Translator.CommandTimeout.HasValue)
            {
                _dbCommand.CommandTimeout = Translator.CommandTimeout.Value;
            }

            SetInputIdentifiers(identifierValues);

            // Execute the query
            long rowsAffected;

            if (null != ResultColumns)
            {
                // If there are result columns, read the server gen results
                rowsAffected = 0;
                var members = TypeHelpers.GetAllStructuralMembers(CurrentValues.StructuralType);
                using (
                    var reader =
                        await
                        _dbCommand.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken).ConfigureAwait(
                            continueOnCapturedContext: false))
                {
                    // Retrieve only the first row from the first result set
                    if (await reader.ReadAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
                    {
                        rowsAffected++;

                        foreach (var resultColumn in ResultColumns
                                 .Select(r => new KeyValuePair <int, PropagatorResult>(GetColumnOrdinal(Translator, reader, r.Key), r.Value))
                                 .OrderBy(r => r.Key)) // order by column ordinal to avoid breaking SequentialAccess readers
                        {
                            var    columnOrdinal = resultColumn.Key;
                            var    columnType    = members[resultColumn.Value.RecordOrdinal].TypeUsage;
                            object value;

                            if (Helper.IsSpatialType(columnType)
                                &&
                                !await
                                reader.IsDBNullAsync(columnOrdinal, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
                            {
                                value =
                                    await
                                    SpatialHelpers.GetSpatialValueAsync(
                                        Translator.MetadataWorkspace, reader, columnType, columnOrdinal, cancellationToken).ConfigureAwait(
                                        continueOnCapturedContext: false);
                            }
                            else
                            {
                                value =
                                    await
                                    reader.GetFieldValueAsync <object>(columnOrdinal, cancellationToken).ConfigureAwait(
                                        continueOnCapturedContext: false);
                            }

                            // register for back-propagation
                            var result = resultColumn.Value;
                            generatedValues.Add(new KeyValuePair <PropagatorResult, object>(result, value));

                            // register identifier if it exists
                            var identifier = result.Identifier;
                            if (PropagatorResult.NullIdentifier != identifier)
                            {
                                identifierValues.Add(identifier, value);
                            }
                        }
                    }

                    // Consume the current reader (and subsequent result sets) so that any errors
                    // executing the function can be intercepted
                    await CommandHelper.ConsumeReaderAsync(reader, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
                }
            }
            else
            {
                rowsAffected = await _dbCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
            }

            return(GetRowsAffected(rowsAffected, Translator));
        }