Beispiel #1
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));
            //    }
            //}
        }
        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));
            }
        }
Beispiel #3
0
 private void _database_GetTotalRowsProgressChanged(object sender, GetTotalRowsArgs e)
 {
     GetTotalRowsProgressChanged?.Invoke(this, e);
 }