Exemplo n.º 1
0
        /// <summary>
        /// Executes the SQL command and returns the output in text format.
        /// </summary>
        private static string ExecuteCommand(MultiShardConnection conn, string commandText)
        {
            try
            {
                StringBuilder output = new StringBuilder();
                output.AppendLine();

                int rowsAffected = 0;

                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText            = commandText;
                    cmd.CommandTimeout         = s_commandLine.QueryTimeout;
                    cmd.CommandTimeoutPerShard = s_commandLine.QueryTimeout;

                    // Execute command and time with a stopwatch
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    cmd.ExecutionPolicy  = s_commandLine.ExecutionPolicy;
                    cmd.ExecutionOptions = s_commandLine.ExecutionOptions;
                    using (MultiShardDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
                    {
                        stopwatch.Stop();

                        // Get column names
                        IEnumerable <string> columnNames = GetColumnNames(reader).ToArray();

                        // Create table formatter
                        TableFormatter tableFormatter = new TableFormatter(columnNames.ToArray());

                        // Read results from db
                        while (reader.Read())
                        {
                            rowsAffected++;

                            // Add the row to the table formatter
                            object[] values = new object[reader.FieldCount];
                            reader.GetValues(values);
                            tableFormatter.AddRow(values);
                        }

                        // Write formatter output
                        output.AppendLine(tableFormatter.ToString());
                    }

                    output.AppendLine();
                    output.AppendFormat("({0} rows affected - {1:hh}:{1:mm}:{1:ss} elapsed)", rowsAffected, stopwatch.Elapsed);
                    output.AppendLine();
                }

                return(output.ToString());
            }
            catch (MultiShardAggregateException e)
            {
                return(e.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the SQL command and returns the output in text format.
        /// </summary>
        private static string ExecuteCommand(MultiShardConnection conn, string commandText)
        {
            try
            {
                StringBuilder output = new StringBuilder();
                output.AppendLine();

                int rowsAffected = 0;

                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = commandText;
                    cmd.CommandTimeout = s_commandLine.QueryTimeout;
                    cmd.CommandTimeoutPerShard = s_commandLine.QueryTimeout;

                    // Execute command and time with a stopwatch
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    cmd.ExecutionPolicy = s_commandLine.ExecutionPolicy;
                    cmd.ExecutionOptions = s_commandLine.ExecutionOptions;
                    using (MultiShardDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
                    {
                        stopwatch.Stop();

                        // Get column names
                        IEnumerable<string> columnNames = GetColumnNames(reader).ToArray();

                        // Create table formatter
                        TableFormatter tableFormatter = new TableFormatter(columnNames.ToArray());

                        // Read results from db
                        while (reader.Read())
                        {
                            rowsAffected++;

                            // Add the row to the table formatter
                            object[] values = new object[reader.FieldCount];
                            reader.GetValues(values);
                            tableFormatter.AddRow(values);
                        }

                        // Write formatter output
                        output.AppendLine(tableFormatter.ToString());
                    }

                    output.AppendLine();
                    output.AppendFormat("({0} rows affected - {1:hh}:{1:mm}:{1:ss} elapsed)", rowsAffected, stopwatch.Elapsed);
                    output.AppendLine();
                }

                return output.ToString();
            }
            catch (MultiShardAggregateException e)
            {
                return e.ToString();
            }
        }