Beispiel #1
0
        //========================================================================================
        // Edit()
        //========================================================================================

        internal override void Edit(River.Orqa.Query.QueryWindow window)
        {
            Statusbar.Message = "Reading text...";

            OracleCommand cmd = new OracleCommand(
                "SELECT text"
                + " FROM dba_source"
                + " WHERE owner='" + schemaName
                + "' AND name='" + Text
                + "' AND type='PACKAGE BODY'"
                + " ORDER BY line",
                dbase.OraConnection
                );

            try
            {
                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.FieldCount > 0)
                {
                    StringBuilder text = new StringBuilder();

                    if (reader.Read())
                    {
                        // Modify first line to insert cmd and qualify name
                        // We purposefully do not trim the end to preserve the space
                        string preamble = reader.GetString(0).Substring("PACKAGE BODY".Length).TrimStart();

                        text.Append(
                            "CREATE OR REPLACE PACKAGE BODY "
                            + schemaName + "." + preamble
                            );

                        // append rest of content
                        while (reader.Read())
                        {
                            text.Append(reader.GetString(0));
                        }

                        window.InsertText(text.ToString());
                        window.MoveHome();
                        window.IsSaved = true;
                        window.SetTitle(schemaName + "." + this.Text);
                    }
                }

                reader.Close();
                reader.Dispose(); reader = null;
            }
            catch (Exception exc)
            {
                River.Orqa.Dialogs.ExceptionDialog.ShowException(exc);
            }

            Statusbar.Message = String.Empty;

            cmd.Dispose();
            cmd = null;
        }
Beispiel #2
0
        //========================================================================================
        // Edit()
        //========================================================================================

        internal override void Edit(River.Orqa.Query.QueryWindow window)
        {
            Statusbar.Message = "Reading view text...";

            string sql =
                @"SELECT V1.owner, V1.view_name, V1.text, V2.comments
    FROM all_views V1
    JOIN all_tab_comments V2
      ON V2.owner = V1.owner
     AND V2.table_name = V1.view_name
   WHERE V1.view_name = '" + Text + @"'
     AND V1.owner = '" + schemaName + "'";

            Logger.WriteLine(sql);

            using (var cmd = new OracleCommand(sql, dbase.OraConnection))
            {
                // required to fetch the "text" column which is a LONG
                cmd.InitialLONGFetchSize = int.MaxValue;

                try
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.FieldCount > 0)
                        {
                            if (reader.Read())
                            {
                                var text = new StringBuilder();

                                text.Append("CREATE OR REPLACE VIEW ");
                                text.Append(schemaName.ToUpper());
                                text.Append(".");
                                text.Append(Text);
                                text.Append("\n");
                                text.Append("AS ");
                                text.Append("\n");

                                string body = reader.GetOracleString(2).ToString().TrimStart();
                                text.Append(body);

                                window.InsertText(text.ToString());
                                window.IsSaved = true;
                                window.SetTitle(schemaName + "." + this.Text);
                            }
                        }

                        reader.Close();
                    }
                }
                catch (Exception exc)
                {
                    River.Orqa.Dialogs.ExceptionDialog.ShowException(exc);
                }

                Statusbar.Message = String.Empty;
            }
        }
Beispiel #3
0
        //========================================================================================
        // Methods
        //========================================================================================

        //========================================================================================
        // Compile()
        //		If an inheritor allows compilation (CanCompile == true), then the inheritor
        //		should override this method to compile itself.
        //========================================================================================

        internal override void Compile(River.Orqa.Query.QueryWindow window)
        {
            Statusbar.Message = "Compiling...";

            string sql = "SELECT text"
                         + " FROM dba_source"
                         + " WHERE owner='" + schemaName
                         + "' AND name='" + Text
                         + "' AND type='TRIGGER'"
                         + " ORDER BY line";

            using (var cmd = new OracleCommand(sql, dbase.OraConnection))
            {
                try
                {
                    using (OracleDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            // Modify first line to insert cmd and qualify name
                            // We purposefully do not trim the end to preserve the space
                            string preamble = reader.GetString(0).Substring("TRIGGER".Length).TrimStart();

                            var text = new StringBuilder();
                            text.Append("CREATE OR REPLACE TRIGGER "
                                        + schemaName + "." + preamble
                                        );

                            // append rest of content
                            while (reader.Read())
                            {
                                text.Append(reader.GetString(0));
                            }

                            window.InsertText(text.ToString());
                            window.IsSaved = true;
                            window.SetTitle(schemaName + "." + this.Text);
                            window.MoveHome();
                        }

                        reader.Close();
                    }

                    Statusbar.Message = String.Empty;
                }
                catch (Exception exc)
                {
                    River.Orqa.Dialogs.ExceptionDialog.ShowException(exc);
                }
            }

            if (window != null)
            {
                window.Execute(ParseMode.Sequential);
            }
        }
Beispiel #4
0
        //========================================================================================
        // Describe()
        //========================================================================================

        protected void Describe(
            string type, string name, string owner, River.Orqa.Query.QueryWindow window)
        {
            window.SetStatusMessage("Generating DDL...");

            worker                     = new BackgroundWorker();
            worker.DoWork             += new DoWorkEventHandler(DoDescribeWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DoDescribeCompleted);
            worker.RunWorkerAsync(new object[] { type, name, owner, window });
        }
Beispiel #5
0
        private void DoDescribeWork(object sender, DoWorkEventArgs e)
        {
            object[] args  = (object[])e.Argument;
            string   type  = (string)args[0];
            string   name  = (string)args[1];
            string   owner = (string)args[2];

            River.Orqa.Query.QueryWindow window = (River.Orqa.Query.QueryWindow)args[3];

            string sql =
                "SELECT dbms_metadata.get_ddl('"
                + type + "','" + name + "','" + owner + "') AS ddl FROM dual";

            Logger.WriteSection("Describe");
            Logger.WriteLine(sql);

            var cmd = new OracleCommand(sql);

            try
            {
                cmd.Connection = dbase.OraConnection;

                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.FieldCount > 0)
                {
                    if (reader.Read())
                    {
                        string ddl = reader.GetString(0).Trim();
                        e.Result = new object[] { ddl, owner, name, window };
                    }
                }

                reader.Close();
                reader.Dispose();
                reader = null;
            }
            catch (Exception exc)
            {
                DialogResult result = MessageBox.Show(null,
                                                      "To fix, try invoking $ORACLE_HOME/rdbms/admin/initmeta.sql.\n\n" +
                                                      "Would you like to view Exception information now?", "initmeta",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    Dialogs.ExceptionDialog.ShowException(exc);
                }
            }

            cmd.Dispose();
            cmd = null;
        }
Beispiel #6
0
        private void DoDescribeCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            object[] args  = (object[])e.Result;
            string   ddl   = (string)args[0];
            string   owner = (string)args[1];
            string   name  = (string)args[2];

            River.Orqa.Query.QueryWindow window = (River.Orqa.Query.QueryWindow)args[3];

            window.InsertText(ddl);
            window.IsSaved = true;
            window.SetTitle(owner + "." + name);
            window.SetStatusMessage("Ready");
        }
Beispiel #7
0
        //========================================================================================
        // Edit()
        //========================================================================================

        internal override void Edit(River.Orqa.Query.QueryWindow window)
        {
            Describe("TYPE", Text, schemaName, window);
        }
Beispiel #8
0
        //========================================================================================
        // Edit()
        //========================================================================================

        internal override void Edit(River.Orqa.Query.QueryWindow window)
        {
            Describe("INDEX", Text.Substring(0, Text.IndexOf(" ")), schemaName, window);
        }
Beispiel #9
0
        //========================================================================================
        // Edit()
        //		If an inheritor allowed editing (CanEdit == true), then the inheritor
        //		should override this method to edit its content.
        //========================================================================================

        internal virtual void Edit(River.Orqa.Query.QueryWindow window)
        {
        }
Beispiel #10
0
        //========================================================================================
        // Compile()
        //		If an inheritor allows compilation (CanCompile == true), then the inheritor
        //		should override this method to compile itself.
        //========================================================================================

        internal virtual void Compile(River.Orqa.Query.QueryWindow window)
        {
        }
Beispiel #11
0
        //========================================================================================
        // Compile()
        //		If an inheritor allows compilation (CanCompile == true), then the inheritor
        //		should override this method to compile itself.
        //========================================================================================

        internal override void Compile(River.Orqa.Query.QueryWindow window)
        {
            Statusbar.Message = "Compiling...";

            OracleCommand cmd = new OracleCommand(
                "SELECT text"
                + "  FROM dba_source"
                + " WHERE owner='" + schemaName
                + "'  AND name='" + Text
                + "'  AND type='PACKAGE BODY'"
                + " ORDER BY line",
                dbase.OraConnection
                );

            try
            {
                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.FieldCount > 0)
                {
                    StringBuilder text = new StringBuilder();

                    if (reader.Read())
                    {
                        // Modify first line to insert cmd and qualify name
                        // We purposefully do not trim the end to preserve the space
                        string preamble = reader.GetString(0).Substring("PACKAGE BODY".Length).TrimStart();

                        if (preamble.IndexOf("wrapped") > 0)
                        {
                            window.Close();

                            MessageBox.Show(
                                "Unable to compile package body; contents are wrapped.",
                                "Wrapped Content",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information
                                );
                        }
                        else
                        {
                            text.Append("CREATE OR REPLACE PACKAGE BODY "
                                        + schemaName + "." + preamble
                                        );

                            // append rest of content
                            while (reader.Read())
                            {
                                text.Append(reader.GetString(0));
                            }

                            window.InsertText(text.ToString());
                            window.IsSaved = true;
                            window.SetTitle(schemaName + "." + this.Text);
                            window.MoveHome();
                        }
                    }
                }

                reader.Close();
                reader.Dispose(); reader = null;

                Statusbar.Message = String.Empty;
            }
            catch (Exception exc)
            {
                River.Orqa.Dialogs.ExceptionDialog.ShowException(exc);
            }

            cmd.Dispose();
            cmd = null;

            if (window != null)
            {
                window.Execute(ParseMode.Sequential);
            }
        }