コード例 #1
0
ファイル: Searcher.cs プロジェクト: perjahn/PerJahnUtils
        public DataTable SearchData(string searchtext, DateTime dt1, DateTime dt2)
        {
            DateTime t1, t2;

            c_d = c_t = c_c = 0;

            _errors = new Dictionary <int, sqlerror>();

            dtResult = new DataTable();
            dtResult.Columns.Add("database");
            dtResult.Columns.Add("table");
            dtResult.Columns.Add("column");
            dtResult.Columns.Add("value");

            t1 = DateTime.Now;
            foreach (string database in databases)
            {
                using (_db = new db(provider, GetConnStr()))
                {
                    _dbname = database;
                    SearchInternal(searchtext, dt1, dt2, database);
                }

                c_d++;
            }
            t2 = DateTime.Now;

            foreach (var error in _errors)
            {
                log.AppendLine(
                    "Error: " + error.Key + Environment.NewLine +
                    "Count: " + error.Value.count + Environment.NewLine +
                    "DB: " + _dbname + Environment.NewLine +
                    "Coltype: " + _coltype + Environment.NewLine +
                    "SQL: " + error.Value.sql + Environment.NewLine +
                    error.Value.Message + Environment.NewLine);
            }

            WriteStats(c_d, c_t, c_c, t1, t2);

            return(dtResult);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: perjahn/PerJahnUtils
        private void GetAllDBs()
        {
            List<string> searchlist;

            string connstr;
            string sql;
            string provider = cbProvider.SelectedValue.ToString();

            // Get database names
            if (provider == "System.Data.SqlClient")
            {
                if (cbSQLLogin.Checked)
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=False; User ID=" + tbUsername.Text + "; Password="******";";
                }
                else
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=True;";
                }
                sql = "select name from sysdatabases order by name";
            }
            else if (provider == "MySql.Data.MySqlClient")
            {
                connstr = "Data Source=" + cbServer.Text + "; Database=information_schema; User ID=" + tbUsername.Text + "; Password="******";";
                sql = "select schema_name name from schemata order by schema_name";
            }
            else  // Unknown provider
            {
                throw new NotImplementedException("Unsupported database provider: '" + provider + "'.");
            }

            System.Data.DataTable dtDBs;

            string dbs = string.Empty;

            using (db mydb = new db(provider, connstr))
            {
                dtDBs = mydb.ExecuteDataTableSQL(sql, null);
            }

            if (cbDBPattern.Checked)
            {
                searchlist = new List<string>();
                foreach (string row in tbDatabases.Text.Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    searchlist.Add(row);
                }
            }
            else
                searchlist = null;

            foreach (DataRow drDB in dtDBs.Rows)
            {
                if (searchlist == null)
                {
                    dbs += drDB["name"].ToString() + Environment.NewLine;
                }
                else
                {
                    string dbname = drDB["name"].ToString();

                    foreach (string search in searchlist)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(
                                        dbname, search, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                        {
                            dbs += dbname + Environment.NewLine;
                            break;
                        }
                    }
                }
            }

            tbDatabases.Text = dbs.TrimEnd();

            return;
        }
コード例 #3
0
        private void GetAllDBs()
        {
            List <string> searchlist;

            string connstr;
            string sql;
            string provider = cbProvider.SelectedValue.ToString();


            // Get database names
            if (provider == "System.Data.SqlClient")
            {
                if (cbSQLLogin.Checked)
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=False; User ID=" + tbUsername.Text + "; Password="******";";
                }
                else
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=True;";
                }
                sql = "select name from sysdatabases order by name";
            }
            else if (provider == "MySql.Data.MySqlClient")
            {
                connstr = "Data Source=" + cbServer.Text + "; Database=information_schema; User ID=" + tbUsername.Text + "; Password="******";";
                sql     = "select schema_name name from schemata order by schema_name";
            }
            else  // Unknown provider
            {
                throw new NotImplementedException("Unsupported database provider: '" + provider + "'.");
            }

            System.Data.DataTable dtDBs;

            string dbs = string.Empty;

            using (db mydb = new db(provider, connstr))
            {
                dtDBs = mydb.ExecuteDataTableSQL(sql, null);
            }


            if (cbDBPattern.Checked)
            {
                searchlist = new List <string>();
                foreach (string row in tbDatabases.Text.Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    searchlist.Add(row);
                }
            }
            else
            {
                searchlist = null;
            }


            foreach (DataRow drDB in dtDBs.Rows)
            {
                if (searchlist == null)
                {
                    dbs += drDB["name"].ToString() + Environment.NewLine;
                }
                else
                {
                    string dbname = drDB["name"].ToString();

                    foreach (string search in searchlist)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(
                                dbname, search, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                        {
                            dbs += dbname + Environment.NewLine;
                            break;
                        }
                    }
                }
            }

            tbDatabases.Text = dbs.TrimEnd();

            return;
        }