private void Export_GetConditionString(MySqlDataReader rdr, MySqlTable table, StringBuilder sb)
        {
            bool isFirst = true;

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                string colName = rdr.GetName(i);

                var col = table.Columns[colName];

                if (col.IsPrimaryKey)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        sb.Append(" and ");
                    }

                    sb.Append("`");
                    sb.Append(colName);
                    sb.Append("`=");
                    sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
                }
            }
        }
        public MySqlViewList(MySqlCommand cmd)
        {
            try
            {
                string dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
                _sqlShowViewList = string.Format("SHOW FULL TABLES FROM `{0}` WHERE Table_type = 'VIEW';", dbname);
                DataTable dt = QueryExpress.GetTable(cmd, _sqlShowViewList);

                foreach (DataRow dr in dt.Rows)
                {
                    _lst.Add(new MySqlView(cmd, dr[0] + ""));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    _allowAccess = false;
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #3
0
        public MySqlTriggerList(MySqlCommand cmd)
        {
            _sqlShowTriggers = "SHOW TRIGGERS;";
            try
            {
                DataTable dt = QueryExpress.GetTable(cmd, _sqlShowTriggers);

                foreach (DataRow dr in dt.Rows)
                {
                    var name = dr["Trigger"].ToString();
                    _lst.Add(name, new MySqlTrigger(cmd, name, dr["Definer"].ToString()));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    _allowAccess = false;
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #4
0
        public void GetTotalRows(MySqlCommand cmd, GetTotalRowsMethod enumGetTotalRowsMode)
        {
            if (enumGetTotalRowsMode == GetTotalRowsMethod.InformationSchema)
            {
                DataTable dtTotalRows = QueryExpress.GetTable(cmd, string.Format("SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '{0}';", _name));

                int _tableCountTotalRow = 0;

                foreach (DataRow dr in dtTotalRows.Rows)
                {
                    string _tbname             = dr["TABLE_NAME"] + "";
                    long   _totalRowsThisTable = 0L;
                    long.TryParse(dr["TABLE_ROWS"] + "", out _totalRowsThisTable);

                    if (_listTable.Contains(_tbname))
                    {
                        _listTable[_tbname].SetTotalRows(_totalRowsThisTable);
                    }
                }
            }
            else if (enumGetTotalRowsMode == GetTotalRowsMethod.SelectCount)
            {
                for (int i = 0; i < _listTable.Count; i++)
                {
                    _listTable[i].GetTotalRowsByCounting(cmd);

                    if (GetTotalRowsProgressChanged != null)
                    {
                        GetTotalRowsProgressChanged(this, new GetTotalRowsArgs(_listTable.Count, i + 1));
                    }
                }
            }
        }
Exemple #5
0
        public MySqlColumnList(MySqlCommand cmd, string tableName)
        {
            _tableName = tableName;
            DataTable dtDataType = QueryExpress.GetTable(cmd, string.Format("SELECT * FROM  `{0}` where 1 = 2;", tableName));

            _sqlShowFullColumns = string.Format("SHOW FULL COLUMNS FROM `{0}`;", tableName);
            DataTable dtColInfo = QueryExpress.GetTable(cmd, _sqlShowFullColumns);

            for (int i = 0; i < dtDataType.Columns.Count; i++)
            {
                string isNullStr = (dtColInfo.Rows[i]["Null"] + "").ToLower();
                bool   isNull    = false;
                if (isNullStr == "yes")
                {
                    isNull = true;
                }

                _lst.Add(new MySqlColumn(
                             dtDataType.Columns[i].ColumnName,
                             dtDataType.Columns[i].DataType,
                             dtColInfo.Rows[i]["Type"] + "",
                             dtColInfo.Rows[i]["Collation"] + "",
                             isNull,
                             dtColInfo.Rows[i]["Key"] + "",
                             dtColInfo.Rows[i]["Default"] + "",
                             dtColInfo.Rows[i]["Extra"] + "",
                             dtColInfo.Rows[i]["Privileges"] + "",
                             dtColInfo.Rows[i]["Comment"] + ""));
            }
        }
        /// <summary>
        ///     Gets the list of document headers.
        /// </summary>
        /// <param name="cmd">The MySqlCommand that will be used to retrieve the database default character set.</param>
        /// <returns>List of document headers.</returns>
        public List <string> GetDocumentHeaders(MySqlCommand cmd)
        {
            if (_documentHeaders != null)
            {
                return(_documentHeaders);
            }
            var databaseCharSet = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_database';",
                                                                1);

            _documentHeaders = new List <string>
            {
                "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;",
                "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;",
                "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;",
                $"/*!40101 SET NAMES {databaseCharSet} */;",
                "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;",
                "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;",
                "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;",
                "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;"
            };

            //_documentHeaders.Add("/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;");
            //_documentHeaders.Add("/*!40103 SET TIME_ZONE='+00:00' */;");

            return(_documentHeaders);
        }
Exemple #7
0
        public MySqlProcedureList(MySqlCommand cmd)
        {
            try
            {
                string dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
                _sqlShowProcedures = string.Format("SHOW PROCEDURE STATUS WHERE UPPER(TRIM(Db))= UPPER(TRIM('{0}'));", dbname);
                DataTable dt = QueryExpress.GetTable(cmd, _sqlShowProcedures);

                foreach (DataRow dr in dt.Rows)
                {
                    _lst.Add(new MySqlProcedure(cmd, dr["Name"] + "", dr["Definer"] + ""));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    _allowAccess = false;
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #8
0
        public MySqlColumnList(MySqlCommand cmd, string tableName)
        {
            _tableName = tableName;
            var dtDataType = QueryExpress.GetTable(cmd, $"SELECT * FROM  `{_tableName}` LIMIT 0;");

            SqlShowFullColumns = $"SHOW FULL COLUMNS FROM `{_tableName}`;";
            var dtColInfo = QueryExpress.GetTable(cmd, SqlShowFullColumns);

            for (var i = 0; i < dtDataType.Columns.Count; i++)
            {
                var isNullStr = (dtColInfo.Rows[i]["Null"] + "").ToLower();
                var isNull    = isNullStr == "yes";

                _lst.Add(new MySqlColumn(
                             dtDataType.Columns[i].ColumnName,
                             dtDataType.Columns[i].DataType,
                             dtColInfo.Rows[i]["Type"] + "",
                             dtColInfo.Rows[i]["Collation"] + "",
                             isNull,
                             dtColInfo.Rows[i]["Key"] + "",
                             dtColInfo.Rows[i]["Default"] + "",
                             dtColInfo.Rows[i]["Extra"] + "",
                             dtColInfo.Rows[i]["Privileges"] + "",
                             dtColInfo.Rows[i]["Comment"] + ""));
            }
        }
Exemple #9
0
        public MySqlFunctionList(MySqlCommand cmd)
        {
            try
            {
                string dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
                _sqlShowFunctions = string.Format("SHOW FUNCTION STATUS WHERE UPPER(TRIM(Db))= UPPER(TRIM('{0}'));", dbname);
                DataTable dt = QueryExpress.GetTable(cmd, _sqlShowFunctions);

                foreach (DataRow dr in dt.Rows)
                {
                    var name = dr["Name"].ToString();
                    _lst.Add(name, new MySqlFunction(cmd, name, dr["Definer"].ToString()));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    _allowAccess = false;
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #10
0
        private string Export_GetValueString(MySqlDataReader rdr, MySqlTable table)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                string columnName = rdr.GetName(i);

                if (table.Columns[columnName].IsGeneratedColumn)
                {
                    continue;
                }

                if (sb.Length == 0)
                {
                    sb.AppendFormat("(");
                }
                else
                {
                    sb.AppendFormat(",");
                }


                object ob  = rdr[i];
                var    col = table.Columns[columnName];

                //sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
                sb.Append(QueryExpress.ConvertToSqlFormat(ob, true, true, col, ExportInfo.BlobExportMode));
            }

            sb.AppendFormat(")");
            return(sb.ToString());
        }
Exemple #11
0
        private static void Export_GetUpdateString(MySqlDataReader rdr, MySqlTable table, StringBuilder sb)
        {
            var isFirst = true;

            for (var i = 0; i < rdr.FieldCount; i++)
            {
                var colName = rdr.GetName(i);

                var col = table.Columns[colName];

                if (!col.IsPrimaryKey)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }

                    sb.Append("`");
                    sb.Append(colName);
                    sb.Append("`=");
                    sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
                }
            }
        }
        private string Export_GetValueString(MySqlDataReader rdr, MySqlTable table)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                if (sb.Length == 0)
                {
                    sb.AppendFormat("(");
                }
                else
                {
                    sb.AppendFormat(",");
                }

                string columnName = rdr.GetName(i);
                object ob         = rdr[i];
                var    col        = table.Columns[columnName];

                sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
            }

            sb.AppendFormat(")");
            return(sb.ToString());
        }
        void Import_SetNames()
        {
            string setname = QueryExpress.ExecuteScalarStr(Command, "SHOW VARIABLES LIKE 'character_set_database';", 1);

            Command.CommandText = string.Format("/*!40101 SET NAMES {0} */;", setname);
            Command.ExecuteNonQuery();
            _nameIsSet = true;
        }
        public MySqlTableList(MySqlCommand cmd)
        {
            _sqlShowFullTables = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE';";
            DataTable dtTableList = QueryExpress.GetTable(cmd, _sqlShowFullTables);

            foreach (DataRow dr in dtTableList.Rows)
            {
                _lst.Add(new MySqlTable(cmd, dr[0] + ""));
            }
        }
Exemple #15
0
        public MySqlTable(MySqlCommand cmd, string name)
        {
            _name = name;
            string sql = string.Format("SHOW CREATE TABLE `{0}`;", name);

            _createTableSql = QueryExpress.ExecuteScalarStr(cmd, sql, 1).Replace(Environment.NewLine, "^~~~~~~^").Replace("\r", "^~~~~~~^").Replace("\n", "^~~~~~~^").Replace("^~~~~~~^", Environment.NewLine).Replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ") + ";";
            _createTableSqlWithoutAutoIncrement = RemoveAutoIncrement(_createTableSql);
            _lst = new MySqlColumnList(cmd, name);
            GetInsertStatementHeaders();
        }
Exemple #16
0
        Dictionary <string, string> Export_RearrangeTableOrderForForeignKey(Dictionary <string, string> dic1)
        {
            System.Data.DataTable dtForeignKeyTables = QueryExpress.GetTable(Command, string.Format("select table_name, referenced_table_name from information_schema.key_column_usage where constraint_schema='{0}' and referenced_table_name IS NOT NULL;", QueryExpress.EscapeStringSequence(_database.Name)));
            if (dtForeignKeyTables.Rows.Count == 0)
            {
                return(dic1);
            }

            Dictionary <string, string> dic2 = new Dictionary <string, string>();

            bool requireLoop = true;

            while (requireLoop)
            {
                requireLoop = false;

                foreach (var kv in dic1)
                {
                    if (dic2.ContainsKey(kv.Key))
                    {
                        continue;
                    }

                    bool handledInForeignKeySearch = false;

                    for (int i = 0; i < dtForeignKeyTables.Rows.Count; i++)
                    {
                        string _tb_name    = dtForeignKeyTables.Rows[i]["table_name"] + "";
                        string _fk_tb_name = dtForeignKeyTables.Rows[i]["referenced_table_name"] + "";

                        if (kv.Key == _tb_name)
                        {
                            handledInForeignKeySearch = true;

                            if (dic2.ContainsKey(_fk_tb_name))
                            {
                                dic2[kv.Key] = kv.Value;
                                requireLoop  = true;
                            }

                            continue;
                        }
                    }

                    if (!handledInForeignKeySearch)
                    {
                        dic2[kv.Key] = kv.Value;
                        requireLoop  = true;
                    }
                }
            }

            return(dic2);
        }
Exemple #17
0
        public void GetTotalRows(MySqlCommand cmd)
        {
            var dtTotalRows = QueryExpress.GetTable(cmd,
                                                    $"SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '{Name}';");

            var tableCountTotalRow = 0;

            foreach (DataRow dr in dtTotalRows.Rows)
            {
                var thisTableName = dr["TABLE_NAME"] + "";

                var totalRowsThisTable = 0L;

                try
                {
                    long.TryParse(dr["TABLE_ROWS"] + "", out totalRowsThisTable);
                }
                catch
                {
                    // ignored
                }

                foreach (var t in Tables)
                {
                    if (t.Name != thisTableName)
                    {
                        continue;
                    }

                    tableCountTotalRow = tableCountTotalRow + 1;

                    t.SetTotalRows(totalRowsThisTable);

                    GetTotalRowsProgressChanged?.Invoke(this, new GetTotalRowsArgs(Tables.Count, tableCountTotalRow));

                    break;
                }
            }


            //for (int i = 0; i < _listTable.Count; i++)
            //{
            //    _listTable[i].GetTotalRows(cmd);

            //    if (GetTotalRowsProgressChanged != null)
            //    {
            //        GetTotalRowsProgressChanged(this, new GetTotalRowsArgs(_listTable.Count, i + 1));
            //    }
            //}
        }
Exemple #18
0
        public void GetTotalRows(MySqlCommand cmd)
        {
            DataTable dtTotalRows = QueryExpress.GetTable(cmd, string.Format("SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '{0}';", _name));

            int _tableCountTotalRow = 0;

            foreach (DataRow dr in dtTotalRows.Rows)
            {
                string _thisTableName = dr["TABLE_NAME"] + "";

                long _totalRowsThisTable = 0L;

                try
                {
                    long.TryParse(dr["TABLE_ROWS"] + "", out _totalRowsThisTable);
                }
                catch { }

                for (int i = 0; i < _listTable.Count; i++)
                {
                    if (_listTable[i].Name != _thisTableName)
                    {
                        continue;
                    }

                    _tableCountTotalRow = _tableCountTotalRow + 1;

                    _listTable[i].SetTotalRows(_totalRowsThisTable);

                    if (GetTotalRowsProgressChanged != null)
                    {
                        GetTotalRowsProgressChanged(this, new GetTotalRowsArgs(_listTable.Count, _tableCountTotalRow));
                    }

                    break;
                }
            }


            //for (int i = 0; i < _listTable.Count; i++)
            //{
            //    _listTable[i].GetTotalRows(cmd);

            //    if (GetTotalRowsProgressChanged != null)
            //    {
            //        GetTotalRowsProgressChanged(this, new GetTotalRowsArgs(_listTable.Count, i + 1));
            //    }
            //}
        }
Exemple #19
0
        public MySqlEvent(MySqlCommand cmd, string eventName, string definer)
        {
            _name = eventName;

            _createEventSql = QueryExpress.ExecuteScalarStr(cmd, string.Format("SHOW CREATE EVENT `{0}`;", _name), "Create Event");

            _createEventSql = _createEventSql.Replace("\r\n", "^~~~~~~~~~~~~~~^");
            _createEventSql = _createEventSql.Replace("\n", "^~~~~~~~~~~~~~~^");
            _createEventSql = _createEventSql.Replace("\r", "^~~~~~~~~~~~~~~^");
            _createEventSql = _createEventSql.Replace("^~~~~~~~~~~~~~~^", "\r\n");

            string[] sa = definer.Split('@');
            definer = string.Format(" DEFINER=`{0}`@`{1}`", sa[0], sa[1]);

            _createEventSqlWithoutDefiner = _createEventSql.Replace(definer, string.Empty);
        }
Exemple #20
0
        public MySqlTrigger(MySqlCommand cmd, string triggerName, string definer)
        {
            _name = triggerName;

            _createTriggerSQL = QueryExpress.ExecuteScalarStr(cmd, string.Format("SHOW CREATE TRIGGER `{0}`;", triggerName), 2);

            _createTriggerSQL = _createTriggerSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^");
            _createTriggerSQL = _createTriggerSQL.Replace("\n", "^~~~~~~~~~~~~~~^");
            _createTriggerSQL = _createTriggerSQL.Replace("\r", "^~~~~~~~~~~~~~~^");
            _createTriggerSQL = _createTriggerSQL.Replace("^~~~~~~~~~~~~~~^", "\r\n");

            string[] sa = definer.Split('@');
            definer = string.Format(" DEFINER=`{0}`@`{1}`", sa[0], sa[1]);

            _createTriggerSQLWithoutDefiner = _createTriggerSQL.Replace(definer, string.Empty);
        }
Exemple #21
0
        private static string Export_GetValueString(MySqlDataReader rdr, MySqlTable table)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < rdr.FieldCount; i++)
            {
                sb.AppendFormat(sb.Length == 0 ? "(" : ",");

                var columnName = rdr.GetName(i);
                var col        = table.Columns[columnName];

                sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
            }

            sb.AppendFormat(")");
            return(sb.ToString());
        }
        public MySqlView(MySqlCommand cmd, string viewName)
        {
            _name = viewName;

            string sqlShowCreate = string.Format("SHOW CREATE VIEW `{0}`;", viewName);

            System.Data.DataTable dtView = QueryExpress.GetTable(cmd, sqlShowCreate);

            _createViewSQL = dtView.Rows[0]["Create View"] + ";";

            _createViewSQL = _createViewSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^");
            _createViewSQL = _createViewSQL.Replace("\n", "^~~~~~~~~~~~~~~^");
            _createViewSQL = _createViewSQL.Replace("\r", "^~~~~~~~~~~~~~~^");
            _createViewSQL = _createViewSQL.Replace("^~~~~~~~~~~~~~~^", "\r\n");

            _createViewSQLWithoutDefiner = QueryExpress.EraseDefiner(_createViewSQL);
        }
Exemple #23
0
        public MySqlFunction(MySqlCommand cmd, string functionName, string definer)
        {
            _name = functionName;

            string sql = string.Format("SHOW CREATE FUNCTION `{0}`;", functionName);

            _createFunctionSQL = QueryExpress.ExecuteScalarStr(cmd, sql, 2);

            _createFunctionSQL = _createFunctionSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^");
            _createFunctionSQL = _createFunctionSQL.Replace("\n", "^~~~~~~~~~~~~~~^");
            _createFunctionSQL = _createFunctionSQL.Replace("\r", "^~~~~~~~~~~~~~~^");
            _createFunctionSQL = _createFunctionSQL.Replace("^~~~~~~~~~~~~~~^", "\r\n");

            string[] sa = definer.Split('@');
            definer = string.Format(" DEFINER=`{0}`@`{1}`", sa[0], sa[1]);

            _createFunctionSqlWithoutDefiner = _createFunctionSQL.Replace(definer, string.Empty);
        }
Exemple #24
0
        public MySqlProcedure(MySqlCommand cmd, string procedureName, string definer)
        {
            _name = procedureName;

            string sql = string.Format("SHOW CREATE PROCEDURE `{0}`;", procedureName);

            _createProcedureSQL = QueryExpress.ExecuteScalarStr(cmd, sql, 2);

            _createProcedureSQL = _createProcedureSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^");
            _createProcedureSQL = _createProcedureSQL.Replace("\n", "^~~~~~~~~~~~~~~^");
            _createProcedureSQL = _createProcedureSQL.Replace("\r", "^~~~~~~~~~~~~~~^");
            _createProcedureSQL = _createProcedureSQL.Replace("^~~~~~~~~~~~~~~^", "\r\n");

            string[] sa = definer.Split('@');
            definer = string.Format(" DEFINER=`{0}`@`{1}`", sa[0], sa[1]);

            _createProcedureSQLWithoutDefiner = _createProcedureSQL.Replace(definer, string.Empty);
        }
Exemple #25
0
        public void GetServerInfo(MySqlCommand cmd)
        {
            _edition                = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'version_comment';", 1);
            _versionNumber          = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'version';", 1);
            _characterSetServer     = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_server';", 1);
            _characterSetSystem     = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_system';", 1);
            _characterSetConnection = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_connection';", 1);
            _characterSetDatabase   = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_database';", 1);

            _currentUserClientHost = QueryExpress.ExecuteScalarStr(cmd, "SELECT current_user;");

            string[] ca = _currentUserClientHost.Split('@');

            _currentUser       = ca[0];
            _currentClientHost = ca[1];

            GetMajorVersionNumber();
        }
Exemple #26
0
        public void GetTotalRows(MySqlCommand cmd, GetTotalRowsMethod enumGetTotalRowsMode)
        {
            int i     = 0;
            var timer = new Timer
            {
                Interval = 10000
            };

            timer.Elapsed += (sender, e) =>
            {
                GetTotalRowsProgressChanged?.Invoke(this, new GetTotalRowsArgs(_listTable.Count, i));
            };

            if (enumGetTotalRowsMode == GetTotalRowsMethod.InformationSchema)
            {
                DataTable dtTotalRows = QueryExpress.GetTable(cmd, string.Format("SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '{0}';", _name));
                timer.Start();
                foreach (DataRow dr in dtTotalRows.Rows)
                {
                    i++;
                    var _tbname = dr["TABLE_NAME"] + "";
                    long.TryParse(dr["TABLE_ROWS"] + "", out var _totalRowsThisTable);

                    if (_listTable.Contains(_tbname))
                    {
                        _listTable[_tbname].SetTotalRows((long)(_totalRowsThisTable * 1.1)); // Adiciona 10% de erro
                    }
                }
                timer.Stop();
                GetTotalRowsProgressChanged?.Invoke(this, new GetTotalRowsArgs(_listTable.Count, _listTable.Count));
            }
            else if (enumGetTotalRowsMode == GetTotalRowsMethod.SelectCount)
            {
                timer.Start();
                foreach (var table in _listTable)
                {
                    i++;
                    table.GetTotalRowsByCounting(cmd);
                }
                timer.Stop();
                GetTotalRowsProgressChanged?.Invoke(this, new GetTotalRowsArgs(_listTable.Count, _listTable.Count));
            }
        }
Exemple #27
0
        public void GetDatabaseInfo(MySqlCommand cmd, bool getTotalRowsForEachTable)
        {
            _name              = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
            _defaultCharSet    = QueryExpress.ExecuteScalarStr(cmd, "SHOW VARIABLES LIKE 'character_set_database';", 1);
            _createDatabaseSql = QueryExpress.ExecuteScalarStr(cmd, string.Format("SHOW CREATE DATABASE `{0}`;", _name), 1).Replace("CREATE DATABASE", "CREATE DATABASE IF NOT EXISTS") + ";";
            _dropDatabaseSql   = string.Format("DROP DATABASE IF EXISTS `{0}`;", _name);

            _listTable     = new MySqlTableList(cmd);
            _listProcedure = new MySqlProcedureList(cmd);
            _listFunction  = new MySqlFunctionList(cmd);
            _listTrigger   = new MySqlTriggerList(cmd);
            _listEvent     = new MySqlEventList(cmd);
            _listView      = new MySqlViewList(cmd);

            if (getTotalRowsForEachTable)
            {
                GetTotalRows(cmd);
            }
        }
        public MySqlTriggerList(MySqlCommand cmd)
        {
            SqlShowTriggers = "SHOW TRIGGERS;";
            try
            {
                var dt = QueryExpress.GetTable(cmd, SqlShowTriggers);

                foreach (DataRow dr in dt.Rows)
                {
                    _lst.Add(new MySqlTrigger(cmd, dr["Trigger"] + "", dr["Definer"] + ""));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    AllowAccess = false;
                }
            }
        }
Exemple #29
0
        public void GetDatabaseInfo(MySqlCommand cmd, bool getTotalRowsForEachTable)
        {
            Name = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
            DefaultCharacterSet = QueryExpress.ExecuteScalarStr(cmd, "SHOW VARIABLES LIKE 'character_set_database';", 1);
            CreateDatabaseSql   =
                QueryExpress.ExecuteScalarStr(cmd, $"SHOW CREATE DATABASE `{Name}`;", 1)
                .Replace("CREATE DATABASE", "CREATE DATABASE IF NOT EXISTS") + ";";
            DropDatabaseSql = $"DROP DATABASE IF EXISTS `{Name}`;";

            Tables     = new MySqlTableList(cmd);
            Procedures = new MySqlProcedureList(cmd);
            Functions  = new MySqlFunctionList(cmd);
            Triggers   = new MySqlTriggerList(cmd);
            Events     = new MySqlEventList(cmd);
            Views      = new MySqlViewList(cmd);

            if (getTotalRowsForEachTable)
            {
                GetTotalRows(cmd);
            }
        }
        public MySqlEventList(MySqlCommand cmd)
        {
            try
            {
                var dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
                SqlShowEvent = $"SHOW EVENTS WHERE UPPER(TRIM(Db))=UPPER(TRIM('{dbname}'));";
                var dt = QueryExpress.GetTable(cmd, SqlShowEvent);

                foreach (DataRow dr in dt.Rows)
                {
                    _lst.Add(new MySqlEvent(cmd, dr["Name"] + "", dr["Definer"] + ""));
                }
            }
            catch (MySqlException myEx)
            {
                if (myEx.Message.ToLower().Contains("access denied"))
                {
                    AllowAccess = false;
                }
            }
        }