Beispiel #1
0
 public void BeginCompare(DbConnectionDO source_conn, string source_db, DbConnectionDO target_conn, string target_db)
 {
     if (msgForm.IsWorking)
     {
         MessageBox.Show("前一个任务还没有执行完成,请等待!");
         return;
     }
     conn_source_str = "server=" + source_conn.HOST + ";port=" + source_conn.PORT + ";user="******";password="******"; database=" + source_db + ";";
     conn_target_str = "server=" + target_conn.HOST + ";port=" + target_conn.PORT + ";user="******";password="******"; database=" + target_db + ";";
     msgForm.ClearText();
     CompareDbSchemaField(source_conn, source_db, target_conn, target_db);
 }
Beispiel #2
0
        private void StartReset(DbConnectionDO conn, string dbname, string tablename, int startNum)
        {
            msgForm.IsWorking = true;
            string conn_str = "server=" + conn.HOST + ";port=" + conn.PORT + ";user="******";password="******"; database=" + dbname + ";";

            msgForm.ClearText();
            msgForm.SetText("正在查询数据记录相关信息");
            MySqlDbHelper dbhelper = new MySqlDbHelper(conn_str);
            string        sql      = "select max(id) from " + tablename;
            object        v        = dbhelper.GetFirstValue(sql);
            int           maxId    = 0;

            if (v != null)
            {
                maxId = Convert.ToInt32(v);
            }
            if (maxId <= 0 || maxId < startNum)
            {
                MessageBox.Show("表起始值无效!");
                return;
            }
            CommittableTransaction trans = new CommittableTransaction(TimeSpan.FromMinutes(120));

            sql = "select count(*) from " + tablename;
            v   = dbhelper.GetFirstValue(sql);
            int count = Convert.ToInt32(v);

            msgForm.SetText(tablename + "表找到" + count + "条数据,最大ID=" + maxId + (count > 10000 ? ",开始分批执行" : ""));
            int           currentId   = 0;
            List <string> sb_updateid = new List <string>();
            int           pcount      = 10000;
            int           execCount   = 0;

            if (count > pcount)
            {
                while (true)
                {
                    int    currentStartNum  = 0;
                    int    currentExecCount = 0;
                    string ss1 = "";
                    sql       = "select id from " + tablename + " where id > " + currentId + " order by id asc limit " + pcount + ";";
                    currentId = ExecResetId(dbhelper, sql, tablename, startNum, trans,
                                            out currentStartNum, out ss1, out currentExecCount);
                    if (currentId <= 0)
                    {
                        break;
                    }
                    startNum   = currentStartNum;
                    execCount += currentExecCount;
                    sb_updateid.Add(ss1);
                    msgForm.SetText("执行到ID=" + currentId + ",剩" + (count - execCount));
                }
            }
            else
            {
                sql = "select id from " + tablename + " order by id asc";
                int    currStartNum;
                string ss1 = "";
                ExecResetId(dbhelper, sql, tablename, startNum, trans, out currStartNum, out ss1, out execCount);
                sb_updateid.Add(ss1);
            }
            msgForm.SetText("执行最后的ID更新");
            int index = 0;

            foreach (string s in sb_updateid)
            {
                msgForm.SetText("执行更新第" + (index + 1) + "批,剩" + (sb_updateid.Count - index - 1));
                new MySqlDbHelper(dbhelper.ConnectionString).RunSql(s, null, null, trans);
                index++;
            }
            trans.Commit();
            msgForm.SetText("执行完成");
            msgForm.IsWorking = false;
        }