Пример #1
0
        //========================================================================================
        // Execute()
        //========================================================================================

        /// <summary>
        /// Executes the specified query.  Results and error messages are stored in
        /// the query itself.
        /// </summary>
        /// <param name="query">The Query describing the SQL statement.</param>

        public void Execute(QueryCollection queries, string basePath, int repeat)
        {
            Logger.WriteLine("QueryDriver.Execute count=[" + queries.Count + "]");

            // fetch this each time incase the user changes it.
            this.timeout = UserOptions.GetInt("connections/queryTimeout") * 1000;

            this.isExecuting = true;
            this.basePath    = basePath;

            try
            {
                Logger.WriteLine("QueryDriver.Execute Starting driver...");

                worker              = new Thread(new ParameterizedThreadStart(Execute));
                worker.Name         = String.Format("QueryDriver{0}", driverID);
                worker.IsBackground = true;

                timer = new System.Threading.Timer(
                    new TimerCallback(Cancel),
                    worker,
                    timeout,
                    Timeout.Infinite
                    );

                var chassis = new Chassis();
                chassis.queries = queries;
                chassis.repeat  = repeat;

                worker.Start(chassis);
            }
            catch (Exception exc)
            {
                Dialogs.ExceptionDialog.ShowException(exc);
            }
        }
Пример #2
0
        private QueryCollection queries;                                // all executed queries


        /// <summary>
        /// Initializes a new instance of the specified type with the given query.
        /// </summary>
        /// <param name="queries">The query collection with summary information.</param>

        public QueriesCompletedEventArgs(QueryCollection queries)
        {
            this.queries = queries;
        }
Пример #3
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;
        }