コード例 #1
0
        private void BuildTextHeader(OraTable table, int[] widths, Notepad pad)
        {
            var head = new StringBuilder();
            var line = new StringBuilder();

            for (int i = 0; i < table.Schema.FieldCount; i++)
            {
                if (i > 0)
                {
                    head.Append(" ");
                    line.Append(" ");
                }

                string name = table.Schema.GetName(i);
                head.Append(name);
                line.Append(new String('-', name.Length));

                if (name.Length < widths[i])
                {
                    int extra = widths[i] - name.Length;



                    head.Append(new String(' ', extra));
                    line.Append(new String('-', extra));
                }
            }

            var savecolor = pad.ForeColor;

            pad.ForeColor = FontsAndColors.IdentifierForeground;
            pad.WriteLine(head.ToString());
            pad.WriteLine(line.ToString());
            pad.ForeColor = savecolor;
        }
コード例 #2
0
        public void SaveFile(string filename)
        {
            if (tabset.SelectedTab == textPage)
            {
                textpad.SaveFile(filename);
            }
            else if (tabset.SelectedTab == gridPage)
            {
                Notepad pad = new Notepad();

                ResultFormat format = (ResultFormat)UserOptions.GetEnumeration(
                    "results/general/format", typeof(ResultFormat));

                if (format == ResultFormat.ColumnAligned)
                {
                    ReportText((Database.Query)grid.Tag, pad);
                }
                else
                {
                    ReportDelimitedText((Database.Query)grid.Tag, format, pad);
                }

                pad.SaveFile(filename);
            }
        }
コード例 #3
0
        //========================================================================================
        // PrintOutputParameters()
        //========================================================================================

        private void PrintOutputParameters(Database.Query query, Notepad output)
        {
            var savecolor = output.ForeColor;

            foreach (Database.Parameter parameter in query.Parameters)
            {
                if (((parameter.Direction &
                      (ParameterDirection.Output | ParameterDirection.ReturnValue)) > 0) &&
                    (parameter.DataType != Oracle.ManagedDataAccess.Client.OracleDbType.RefCursor))
                {
                    output.ForeColor = Color.FromArgb(0x6E96BE);                     // "Number-style" blue;
                    output.WriteLine(
                        "Output parameter: '" + parameter.Name
                        + "' = [" + parameter.Value.ToString().Trim() + "]");
                }
            }

            output.ForeColor = savecolor;
        }
コード例 #4
0
        // used by both delimited-text and grid-export...
        private void ReportDelimitedText(Database.Query query, ResultFormat format, Notepad pad)
        {
            bool outputQuery = UserOptions.GetBoolean("results/general/outputQuery");
            bool printHeader = UserOptions.GetBoolean("results/general/printHeader");

            StringBuilder sult      = new StringBuilder();
            StringBuilder line      = new StringBuilder();
            string        delimiter = ",";

            switch (format)
            {
            case ResultFormat.CommaDelimited:
                delimiter = ",";
                break;

            case ResultFormat.TabDelimited:
                delimiter = new String((char)0x09, 1);
                break;

            case ResultFormat.SpaceDelimited:
                delimiter = " ";
                break;

            case ResultFormat.CustomDelimited:
                delimiter = UserOptions.GetString("results/general/delimiter");
                break;
            }

            if (outputQuery)
            {
                PrintQueryBox(query.SQL, pad);
            }

            OraData data = query.Data;

            foreach (OraTable table in data)
            {
                if (printHeader && (table.Count > 0))
                {
                    for (int i = 0; i < table.FieldCount; i++)
                    {
                        if (i > 0)
                        {
                            line.Append(delimiter);
                        }
                        line.Append(table.Schema[i].ColumnName);
                    }

                    sult.Append(line.ToString() + CR);
                }

                foreach (OraRow row in table)
                {
                    line.Length = 0;

                    for (int i = 0; i < table.FieldCount; i++)
                    {
                        if (i > 0)
                        {
                            line.Append(delimiter);
                        }
                        if (row[i] != null)
                        {
                            line.Append(row[i].ToString());
                        }
                    }

                    sult.Append(line.ToString() + CR);
                }

                pad.Write(sult.ToString());
                pad.WriteNote(CR + "(" + query.AffectedRecords + " row(s) affected)");
            }
        }
コード例 #5
0
        private void ReportText(Database.Query query, Notepad pad)
        {
            bool outputQuery   = UserOptions.GetBoolean("results/general/outputQuery");
            bool printHeader   = UserOptions.GetBoolean("results/general/printHeader");
            bool rightAlign    = UserOptions.GetBoolean("results/general/rightAlign");
            bool cleanNewlines = UserOptions.GetBoolean("results/general/cleanNewlines");
            bool ratype        = rightAlign;
            int  totalRows     = 0;

            OraData data = query.Data;

            var    line = new StringBuilder();
            string text;

            if (resultCount > 0)
            {
                var color = pad.ForeColor;
                pad.ForeColor = Color.FromArgb(0x6E96BE);                 // "Number-style" blue
                pad.WriteLine(CR + new String((char)0x2550, 100) + CR);
                pad.ForeColor = color;
            }

            if (outputQuery)
            {
                PrintQueryBox(query.SQL, pad);
            }

            if (query.HasOutputs)
            {
                PrintOutputParameters(query, pad);
            }

            for (int t = 0; t < data.Count; t++)
            {
                OraTable table = data[t];

                if (t > 0)
                {
                    var color = pad.ForeColor;
                    pad.ForeColor = Color.FromArgb(0x6E96BE);                     // "Number-style" blue
                    pad.WriteLine(CR + new String((char)0x2550, 100));
                    pad.ForeColor = color;
                }

                int[] widths = null;
                if (table.Count > 0)
                {
                    widths = MeasureColumns(table);

                    if (printHeader)
                    {
                        BuildTextHeader(table, widths, pad);
                    }

                    foreach (OraRow row in table)
                    {
                        line = new StringBuilder();

                        for (int i = 0; i < table.FieldCount; i++)
                        {
                            if (i > 0)
                            {
                                line.Append(" ");
                            }

                            if (row[i] == null)
                            {
                                text = "...";
                            }
                            else if (table.Schema[i].DataType == typeof(Byte[]))
                            {
                                if (row[i].GetType() == typeof(DBNull))
                                {
                                    text = String.Empty;
                                }
                                else
                                {
                                    Byte[] bytes = (Byte[])row[i];
                                    text = String.Join(
                                        String.Empty,
                                        bytes.Select(b => b.ToString("X2")).ToArray());
                                }
                            }
                            else
                            {
                                text = row[i].ToString();
                            }

                            if (cleanNewlines)
                            {
                                text = text.Replace("\n", String.Empty).Replace("\r", String.Empty);
                            }

                            if (text.Length > widths[i])
                            {
                                line.Append(text.Substring(0, widths[i]));
                            }
                            else
                            {
                                if (rightAlign)
                                {
                                    TypeCode code = Type.GetTypeCode(row[i].GetType());
                                    ratype = ((code != TypeCode.Boolean) &&
                                              (code != TypeCode.Char) &&
                                              (code != TypeCode.String));
                                }

                                if (ratype)
                                {
                                    line.Append(new String(' ', widths[i] - text.Length) + text);
                                }
                                else
                                {
                                    line.Append(text + new String(' ', widths[i] - text.Length));
                                }
                            }
                        }

                        pad.WriteLine(line.ToString());
                    }
                }

                pad.WriteLine();
                pad.WriteNote(String.Format(RxRowsAffected, table.Count));

                totalRows += table.Count;
            }

            if (data.Count == 0)
            {
                totalRows = query.AffectedRecords;
            }

            if (data.Count != 1)
            {
                string msg;
                if (totalRows < 0)
                {
                    msg = RxCompleted;
                }
                else
                {
                    msg = String.Format(RxTotalRowsAffected, totalRows);
                }

                pad.WriteNote(CR + msg);
            }
        }
コード例 #6
0
        //========================================================================================
        // Add()
        //========================================================================================

        /// <summary>
        /// Displays the results of the given query.
        /// </summary>
        /// <param name="query">The query to report.</param>

        public void Add(Database.Query query)
        {
            Logger.WriteLine("Adding result with target [" + resultTarget + "]");

            Notepad msgTarget = textpad;

            if ((int)resultTarget < 0)                                          // TODO: why!?
            {
                resultTarget = ResultTarget.Text;
            }

            if (!query.HideResults)
            {
                if (query.QueryType == QueryType.SqlPlus)
                {
                    LoadFile(query.OutputFilename);
                }
                else
                {
                    switch (resultTarget)
                    {
                    case ResultTarget.Text:
                        ResultFormat format = (ResultFormat)UserOptions.GetEnumeration(
                            "results/general/format", typeof(ResultFormat));

                        if (format == ResultFormat.ColumnAligned)
                        {
                            ReportText(query);
                        }
                        else
                        {
                            ReportDelimitedText(query, format);
                        }
                        break;

                    case ResultTarget.Grid:
                        ReportGrid(query);
                        msgTarget = msgpad;
                        break;

                    case ResultTarget.Xml:
                        ReportXml(query);
                        break;
                    }
                }
            }

            if (query.Messages.Count > 0)
            {
                ReportMessages(query.Messages, msgTarget, query.HideResults);
            }
            else if (query.HideResults)
            {
                textpad.WriteNote(CR + RxNoMessages);
            }

            if (UserOptions.GetBoolean("results/general/dbmsOutput"))
            {
                if (query.OutputLines.Count > 0)
                {
                    ReportOutputLines(query.OutputLines);
                }
            }

            resultCount++;
        }