Esempio n. 1
0
        /// <summary>
        /// Initializes a new query driver for the specified connection.  A single
        /// driver is created for each QueryWindow.
        /// </summary>

        public QueryDriver(DatabaseConnection dbase, River.Orqa.Browser.IBrowser browser)
        {
            this.driverID        = ++QueryDriver.driverCount;
            this.dbase           = dbase;
            this.browser         = browser;
            this.isOutputEnabled = UserOptions.GetBoolean("results/general/dbmsOutput");

            Reset();
        }
Esempio n. 2
0
        //========================================================================================
        // ReportGrid()
        //========================================================================================

        #region ReportGrid

        private void ReportGrid(Database.Query query)
        {
            DataGridView g = (resultCount == 0 ? grid : AddGrid());

            if (query.Data.Count > 0)
            {
                OraTable table = query.Data[0];
                for (int c = 0; c < table.Schema.FieldCount; c++)
                {
                    g.Columns.Add(table.Schema[c].ColumnName, table.Schema[c].ColumnName);
                }

                foreach (var row in table)
                {
                    var values = new List <String>();
                    foreach (object value in row)
                    {
                        if (value == null)
                        {
                            values.Add("...");
                        }
                        else
                        {
                            values.Add(value.ToString());
                        }
                    }

                    g.Rows.Add(values.ToArray());
                }
            }

            g.Tag = query;

            bool outputQuery = UserOptions.GetBoolean("results/general/outputQuery");

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

            msgpad.WriteNote(CR + "(" + query.AffectedRecords + " row(s) affected)");
        }
Esempio n. 3
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)");
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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++;
        }
Esempio n. 6
0
        //========================================================================================
        // SetOptions()
        //========================================================================================

        public void SetOptions()
        {
            string fontName = UserOptions.GetString("editor/editorFonts/font/family");
            int    fontSize = UserOptions.GetInt("editor/editorFonts/font/size");

            editor.Font = new Font(fontName, fontSize);

            bool            beyondEof       = UserOptions.GetBoolean("editor/general/beyondEof");
            bool            beyondEoln      = UserOptions.GetBoolean("editor/general/beyondEoln");
            NavigateOptions navigateOptions = NavigateOptions.DownAtLineEnd | NavigateOptions.UpAtLineBegin;

            if (beyondEof)
            {
                navigateOptions |= NavigateOptions.BeyondEof;
            }
            if (beyondEoln)
            {
                navigateOptions |= NavigateOptions.BeyondEol;
            }
            editor.NavigateOptions = navigateOptions;

            editor.IndentOptions = IndentOptions.AutoIndent;

            bool verticalScroll   = UserOptions.GetBoolean("editor/general/verticalScroll");
            bool horizontalScroll = UserOptions.GetBoolean("editor/general/horizontalScroll");

            if (verticalScroll && horizontalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
            }
            else if (verticalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
            }
            else if (horizontalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedHorizontal;
            }
            else
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.None;
            }

            bool showGutter  = UserOptions.GetBoolean("editor/general/showGutter");
            int  gutterWidth = UserOptions.GetInt("editor/general/gutterWidth");
            bool lineNumbers = UserOptions.GetBoolean("editor/general/lineNumbers");

            editor.Gutter.Visible = showGutter;
            editor.Gutter.Width   = gutterWidth;
            editor.Gutter.Options = (lineNumbers ? GutterOptions.PaintLineNumbers | GutterOptions.PaintLinesOnGutter : GutterOptions.None);

            bool showMargin     = UserOptions.GetBoolean("editor/general/showMargin");
            int  marginPosition = UserOptions.GetInt("editor/general/marginPosition");
            bool wordWrap       = UserOptions.GetBoolean("editor/general/wordWrap");
            bool wrapAtMargin   = UserOptions.GetBoolean("editor/general/wrapAtMargin");

            editor.Margin.Visible  = showMargin;
            editor.Margin.Position = marginPosition;
            editor.WordWrap        = wordWrap;
            editor.WrapAtMargin    = wrapAtMargin;

            SyntaxSettings settings = new SyntaxSettings();

            bool keepTabs = UserOptions.GetBoolean("editor/editorTabs/keepTabs");
            int  tabSize  = UserOptions.GetInt("editor/editorTabs/size");

            editor.Source.Lines.TabStops = new int[1] {
                tabSize
            };
            editor.Source.Lines.UseSpaces = !keepTabs;

            // set lex styles

            XPathNavigator nav = UserOptions.OptionsDoc.CreateNavigator();

            nav.MoveToFirstChild();
            nav = nav.SelectSingleNode("editor/editorFonts/lexStyles");

            nav.MoveToFirstChild();
            LexStyleItem item;
            string       colorName;

            var foreground = FontsAndColors.PlainTextForeground;
            var background = FontsAndColors.PlainTextBackground;

            do
            {
                if (nav.NodeType == XPathNodeType.Element)
                {
                    item              = new LexStyleItem();
                    item.Name         = nav.LocalName;
                    item.InternalName = nav.LocalName;

                    colorName      = nav.GetAttribute("foreColor", nav.NamespaceURI);
                    item.ForeColor = Color.FromName(colorName);
                    if (!item.ForeColor.IsKnownColor)
                    {
                        item.ForeColor = Color.FromArgb(unchecked ((int)uint.Parse(
                                                                       colorName, System.Globalization.NumberStyles.HexNumber)));
                    }

                    if (item.Name.Equals("whitespace"))
                    {
                        foreground = item.ForeColor;
                    }

                    colorName      = nav.GetAttribute("backColor", nav.NamespaceURI);
                    item.BackColor = Color.FromName(colorName);
                    if (!item.BackColor.IsKnownColor)
                    {
                        item.BackColor = Color.FromArgb(unchecked ((int)uint.Parse(
                                                                       colorName, System.Globalization.NumberStyles.HexNumber)));
                    }

                    if (item.Name.Equals("whitespace"))
                    {
                        background = item.BackColor;
                    }

                    item.FontStyle
                        = (FontStyle)Enum.Parse(
                              typeof(FontStyle), nav.GetAttribute("style", nav.NamespaceURI));

                    ApplyLeXStyle(item);
                }
            }while (nav.MoveToNext(XPathNodeType.Element));

            editor.ForeColor = foreground;
            editor.BackColor = background;
            editor.Refresh();
        }