Пример #1
0
        void MnuSchemaClick(object sender, EventArgs e)
        {
            if (currentDSN == null)
            {
                MessageBox.Show("Select a data source", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            lblCurrentStatus.Text = "Building schema...";
            this.Cursor           = Cursors.WaitCursor;
            Application.DoEvents();
            DateTime start = DateTime.Now;

            mnuSchema.Enabled = false;
            myTreeView1.Nodes.Clear();

            SchemaArgs args = new SchemaArgs();

            args.ConString = string.Format("DSN={0};Uid={1};Pwd={2};", currentDSN.GetDSNName(), txtUserName.Text, txtPassword.Text);

            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            worker.DoWork             += new DoWorkEventHandler(SchemaWorker_DoWork);
            worker.ProgressChanged    += new ProgressChangedEventHandler(SchemaWorker_ProgressChanged);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SchemaWorker_RunWorkerCompleted);

            worker.RunWorkerAsync(args);
        }
Пример #2
0
        void SchemaWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SchemaArgs args = (SchemaArgs)e.Argument;

            BackgroundWorker worker = (BackgroundWorker)sender;

            Program.logger.Debug("Connection string: " + args.ConString);

            using (OdbcConnection con = new OdbcConnection(args.ConString))
            {
                con.Open();

                Program.logger.Debug("Getting restrictions");
                DataRow[] restrictionList = con.GetSchema("Restrictions").Select("CollectionName = 'Tables'");

                // Build column restrictions
                foreach (DataRow r in restrictionList)
                {
                    string colName = r[1].ToString();
                    Program.logger.Debug("Restrictions: " + colName);
                }


                Program.logger.Debug("Getting table list");
                DataTable result = con.GetSchema(OdbcMetaDataCollectionNames.Tables);

                myTreeView1.Nodes.Clear();

                bool isOracle = currentDSN.GetDSNDriverName().ToLower().Contains("oracle");

                List <DataRow> tables = new List <DataRow>();
                foreach (DataRow tab in result.Rows)
                {
                    tables.Add(tab);
                }

                // Write the values
                foreach (DataRow tab in tables.Where(x => !x.IsNull(2)).OrderBy(x => x[2].ToString()))
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    Program.logger.Debug("Getting table properties");
                    Table table = new Table();
                    if (!tab.IsNull(0))
                    {
                        table.Database = tab[0].ToString();
                    }
                    if (!tab.IsNull(1))
                    {
                        table.Owner = tab[1].ToString();
                    }
                    if (!tab.IsNull(2))
                    {
                        table.Name = tab[2].ToString();
                    }
                    if (!tab.IsNull(3))
                    {
                        table.Type = tab[3].ToString();
                    }

                    if (isOracle)
                    {
                        if (settings.OracleIgnoredSchemaArray.Contains(table.Owner))
                        {
                            continue;
                        }
                    }

                    table.Text               = table.ToString();
                    table.ImageIndex         = 0;
                    table.SelectedImageIndex = 1;

                    // Build column restrictions
                    foreach (DataRow r in restrictionList)
                    {
                        string colName = r[1].ToString();
                        int    col     = result.Columns.IndexOf(colName);
                        if (col == -1)
                        {
                            table.Restrictions.Add(null);
                        }
                        else if (tab.IsNull(col))
                        {
                            table.Restrictions.Add(null);
                        }
                        else
                        {
                            string restriction = tab[col].ToString();
                            table.Restrictions.Add(restriction);
                        }
                    }

                    table.Nodes.Add("Loading...");

                    worker.ReportProgress(0, table);
                }
            }
        }