Exemple #1
0
        //========================================================================================
        // EnsurePlanTable()
        //========================================================================================

        private bool EnsurePlanTable(Query query, string tableName)
        {
            bool confirmed = false;

            string sql
                = "SELECT table_name"
                  + " FROM All_Tables"
                  + " WHERE owner='" + dbase.DefaultSchema
                  + "'  AND table_name='" + tableName
                  + "'";

            using (var cmd = new OracleCommand(sql, dbase.OraConnection))
            {
                using (var reader = cmd.ExecuteReader())
                {
                    confirmed = reader.Read();
                    reader.Close();
                }

                if (!confirmed)
                {
                    sql = River.Orqa.Properties.Resources.ExplainPlanTable;
                    var parser = new StatementParser();
                    StatementCollection statements = parser.Parse(sql.Replace("PLAN_TABLE", tableName));

                    cmd.CommandText = statements[0];

                    try
                    {
                        int count = cmd.ExecuteNonQuery();
                        confirmed = true;
                    }
                    catch (OracleException exc)
                    {
                        query.AddMessage(exc);
                    }
                    catch (Exception exc)
                    {
                        if (exc.Message == String.Empty)
                        {
                            query.AddMessage(new Message(Message.MessageType.Error, exc.StackTrace));
                        }
                        else
                        {
                            query.AddMessage(new Message(Message.MessageType.Error, exc.Message));
                        }
                    }
                }
            }

            return(confirmed);
        }
Exemple #2
0
        //========================================================================================
        // ExecuteExternalScript()
        //========================================================================================

        private void ExecuteExternalScript(Query query)
        {
            isNested = true;

            try
            {
                string filnam = query.SQL.Substring(1);
                if (filnam[filnam.Length - 1] == ';')
                {
                    filnam = filnam.Substring(0, filnam.Length - 1);
                }

                if (Path.GetDirectoryName(filnam) == String.Empty)
                {
                    filnam = basePath + "\\" + filnam;
                }

                StreamReader reader = File.OpenText(filnam);
                string       text   = reader.ReadToEnd().Trim();
                reader.Close();

                if (text.Length == 0)
                {
                    return;
                }

                string savePath = basePath;
                basePath = Path.GetDirectoryName(filnam);

                // create nested query collection processing...

                var queries = new QueryCollection();
                var parser  = new StatementParser();
                StatementCollection statements = parser.Parse(text);

                // build collection of parsed queries
                Query q;
                System.Collections.Specialized.StringEnumerator e = statements.GetEnumerator();
                while (e.MoveNext())
                {
                    q = new Query(e.Current);
                    parser.ParseStatement(dbase, q, browser);
                    queries.Add(q);
                }
                //[end create nested]

                // execute query collection

                try
                {
                    foreach (Query q2 in queries)
                    {
                        ExecuteQuery(q2);
                    }
                }
                catch (Exception exc)
                {
                    Dialogs.ExceptionDialog.ShowException(exc);
                }
                finally
                {
                    basePath = savePath;
                }
            }
            catch (Exception exc)
            {
                query.AddMessage(exc);
            }

            isNested = false;
        }