public override string GetInfoByFile(string dirName, string fileName, ref DbModels list)
 {
     try
     {
         list.DbModel = Tools.GetModel <DBSetting>(dirName, fileName);
         return(null);
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }
 public override string GetInfoByFile(string dirName, string fileName, ref DbModels list)
 {
     try
     {
         list.Views = new Dictionary <string, ViewInfo>();
         foreach (var item in Tools.GetInfo <ViewInfo>(dirName, fileName))
         {
             list.Views.Add(item.Name, item);
         }
         return(null);
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }
Exemplo n.º 3
0
 public override string GetInfoByFile(string dirName, string fileName, ref DbModels list)
 {
     try
     {
         list.Tables = new Dictionary<string, TableInfo>();
         foreach (var item in Tools.GetInfo<TableInfo>(dirName, fileName))
         {
             list.Tables.Add(item.Name, item);
         }
         return null;
     }
     catch (Exception e)
     {
         return e.Message;
     }
 }
Exemplo n.º 4
0
        private DbModels GetEmptyDbModel(DBDataSourceType sourceType)
        {
            DbModels rel = new DbModels();

            if (sourceType == DBDataSourceType.Empty)
            {
                rel.DbModel = new DBSetting()
                {
                    DbName = "NULL", SchemaName = "NULL"
                };
                rel.Functions = new Dictionary <string, Function>();
                rel.Procs     = new Dictionary <string, Function>();
                rel.Tables    = new Dictionary <string, TableInfo>();
                rel.Triggers  = new Dictionary <string, Trigger>();
                rel.Views     = new Dictionary <string, ViewInfo>();
            }
            return(rel);
        }
Exemplo n.º 5
0
        private void StartCompare()
        {
            config.Setting = cs;


            if (oldDataSource == null || newDataSource == null)
            {
                SetStatus(false);
                AppendOutputText("无数据源", OutputType.Error);
                MessageBox.Show("无数据源", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            DbModels oldDbModels = GetEmptyDbModel(oldDataSource.Type);
            DbModels newDbModels = GetEmptyDbModel(newDataSource.Type);


            cs.CheckCommon             = this.cheComm.Checked;
            cs.OutputComment           = xhkOutComment.Checked;
            cs.OutputDeleteSql         = chkOutDeleteSql.Checked;
            cs.OutputDeleteSqlIsCommon = chkOutDeleteSqlIsCommon.Checked;
            cs.IsSearFunc  = this.chkDiffFunc.Checked;
            cs.IsSearTable = this.chkDiffTable.Checked;
            cs.IsSearProc  = this.chkDiffProc.Checked;
            cs.IsSearTri   = this.chkDiffTrigger.Checked;
            cs.IsSearView  = this.chkDiffView.Checked;



            //处理数据源字符串
            config.OldConnection.ConnectionString = GetShowConnectionString(oldDataSource);
            config.NewConnection.ConnectionString = GetShowConnectionString(newDataSource);
            config.OldConnection.ProviderName     = oldDataSource.ProviderName;
            config.NewConnection.ProviderName     = newDataSource.ProviderName;

            startTime = DateTime.Now;
            SetTotalTime();

            ClearOutputText();
            //throw new Exception("testing");
            List <string>   tempList    = new List <string>();
            List <Function> tempFunList = new List <Function>();
            string          tempStt     = "";
            string          tempStr     = "";
            bool            tempBool    = false;

            SetStatus(true);

            AppendOutputText("我们正在准备一些事情,请耐心等待\n", OutputType.Comment);



            //获取数据库信息
            tempBool = true;
            DataBaseCompareAndShowResultHelper dbHelper = new DataBaseCompareAndShowResultHelper();

            dbHelper.OutputText          = AppendOutputText;
            dbHelper.ReplaceLastLineText = ReplaceLastLineText;


            #region 获取数据源

            if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
            {
                ////测试连接到数据库,以免报错
                //AppendOutputText("正在检查连接到新数据库的状态,请耐心等待\n", OutputType.Comment);
                //if (!helper.TestLine(10000))
                //{
                //    AppendOutputText("新数据库连接失败\n", OutputType.Comment);
                //    MessageBox.Show("新数据库连接失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    SetStatus(false);
                //    return;
                //}
                //else
                //{
                //    AppendOutputText("新数据库连接成功\n", OutputType.Comment);
                //}


                AppendOutputText("从文件中获取数据库信息\n", OutputType.Comment);
                tempStt = dbHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.DBSetting, ref oldDbModels);
                if (!string.IsNullOrWhiteSpace(tempStt))
                {
                    tempBool = false;
                    AppendOutputText(tempStt + "\r\n", OutputType.Error);
                }
            }
            else if (oldDataSource.Type == DBDataSourceType.MySql)
            {
                AppendOutputText("从数据库中获取数据库信息\n", OutputType.Comment);
                if (!dbHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                {
                    tempBool = false;
                }
            }
            if (newDataSource.Type == DBDataSourceType.DataSourceFile)
            {
                ////测试连接到数据库,以免报错
                //AppendOutputText("正在检查连接到旧数据库的状态,请耐心等待\n", OutputType.Comment);
                //if (!helper.TestLine(10000))
                //{
                //    AppendOutputText("旧数据库连接失败\n", OutputType.Comment);
                //    MessageBox.Show("旧数据库连接失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    SetStatus(false);
                //    return;
                //}
                //else
                //{
                //    AppendOutputText("旧数据库连接成功\n", OutputType.Comment);
                //}


                AppendOutputText("从文件中获取数据库信息\n", OutputType.Comment);
                tempStt = dbHelper.GetInfoByFile(newDataSource.Value, newpathCs.DBSetting, ref newDbModels);
                if (!string.IsNullOrWhiteSpace(tempStt))
                {
                    tempBool = false;
                    AppendOutputText(tempStt + "\r\n", OutputType.Error);
                }
            }
            else if (newDataSource.Type == DBDataSourceType.MySql)
            {
                AppendOutputText("从数据库中获取数据库信息\n", OutputType.Comment);
                if (!dbHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                {
                    tempBool = false;
                }
            }
            #endregion

            string resultStr = "";
            if (tempBool)
            {
                resultStr = Tools.GetDirFullPath(string.Format("/result/{0}-{1}-{2}/", DateTime.Now.ToString("yyyyMMddHHmmss"), oldDbModels.DbModel.DbName, newDbModels.DbModel.DbName));


                File.AppendAllText(resultStr + oldpathCs.DBSetting, JsonConvert.SerializeObject(oldDbModels.DbModel));
                File.AppendAllText(resultStr + newpathCs.DBSetting, JsonConvert.SerializeObject(newDbModels.DbModel));
            }
            else
            {
                throw new Exception("获取数据库信息失败");
            }


            ////从网卡层面判断是否联网
            //if (!Win32API.InternetGetConnectedState(ref int tempInx, 0))
            //{
            //    AppendOutputText("请检查你的网络状态", OutputType.Error);
            //    MessageBox.Show("结束对比:请检查你的网络状态", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    SetStatus(false);
            //    return;
            //}


            AppendOutputText("\n", OutputType.None);
            File.AppendAllText(resultStr + oldpathCs.Path, JsonConvert.SerializeObject(config));


            if (cs.IsDiff)
            {
                dbHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);

                if (string.IsNullOrEmpty(errorString) && tempBool)
                {
                    AppendOutputText("对比完毕\n\n", OutputType.Comment);
                    //compIsError = true;
                }
                else
                {
                    //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                    //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                File.AppendAllText(resultStr + diffpathCs.DBSetting, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
            }
            tempStr = RtxResult.Text;


            if (cs.IsSearTable)
            {
                tempBool = true;
                TableCompareAndShowResultHelper viewHelper = new TableCompareAndShowResultHelper();
                viewHelper.OutputText          = AppendOutputText;
                viewHelper.ReplaceLastLineText = ReplaceLastLineText;



                #region 获取数据源

                if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取表结构\n", OutputType.Comment);
                    tempStt = viewHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.Tables, ref oldDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Tables, JsonConvert.SerializeObject(oldDbModels.Tables.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (oldDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取表结构\n", OutputType.Comment);
                    if (viewHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Tables, JsonConvert.SerializeObject(oldDbModels.Tables.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }
                if (newDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取表结构\n", OutputType.Comment);
                    tempStt = viewHelper.GetInfoByFile(newDataSource.Value, newpathCs.Tables, ref newDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + newpathCs.Tables, JsonConvert.SerializeObject(newDbModels.Tables.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (newDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取表结构\n", OutputType.Comment);
                    if (viewHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                    {
                        File.AppendAllText(resultStr + newpathCs.Tables, JsonConvert.SerializeObject(newDbModels.Tables.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                #endregion


                if (cs.IsDiff)
                {
                    viewHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);

                    if (string.IsNullOrEmpty(errorString) && tempBool)
                    {
                        AppendOutputText("对比完毕\n\n", OutputType.Comment);
                        //compIsError = true;
                    }
                    else
                    {
                        //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                        //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    File.AppendAllText(resultStr + diffpathCs.Tables, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
                }
                tempStr = RtxResult.Text;
            }


            if (cs.IsSearView)
            {
                tempBool = true;
                ViewCompareAndShowResultHelper viewHelper = new ViewCompareAndShowResultHelper();
                viewHelper.OutputText          = AppendOutputText;
                viewHelper.ReplaceLastLineText = ReplaceLastLineText;

                #region 获取数据源

                if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取视图\n", OutputType.Comment);
                    tempStt = viewHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.Views, ref oldDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Views, JsonConvert.SerializeObject(oldDbModels.Views.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (oldDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取视图\n", OutputType.Comment);
                    if (viewHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Views, JsonConvert.SerializeObject(oldDbModels.Views.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                if (newDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取视图\n", OutputType.Comment);
                    tempStt = viewHelper.GetInfoByFile(newDataSource.Value, newpathCs.Views, ref newDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + newpathCs.Views, JsonConvert.SerializeObject(newDbModels.Views.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (newDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取视图\n", OutputType.Comment);
                    if (viewHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                    {
                        File.AppendAllText(resultStr + newpathCs.Views, JsonConvert.SerializeObject(newDbModels.Views.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                #endregion

                if (cs.IsDiff)
                {
                    viewHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);

                    if (string.IsNullOrEmpty(errorString) && tempBool)
                    {
                        AppendOutputText("对比完毕\n\n", OutputType.Comment);
                    }
                    else
                    {
                        //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                        //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    File.AppendAllText(resultStr + diffpathCs.Views, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
                }
                tempStr = RtxResult.Text;
            }

            if (cs.IsSearTri)
            {
                tempBool = true;
                TrigCompareAndShowResultHelper trigHelper = new TrigCompareAndShowResultHelper();
                trigHelper.OutputText          = AppendOutputText;
                trigHelper.ReplaceLastLineText = ReplaceLastLineText;


                #region 获取数据源


                if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取触发器\n", OutputType.Comment);
                    tempStt = trigHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.Trigs, ref oldDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Trigs, JsonConvert.SerializeObject(oldDbModels.Triggers.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (oldDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取触发器\n", OutputType.Comment);
                    if (trigHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Trigs, JsonConvert.SerializeObject(oldDbModels.Triggers.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                if (newDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取触发器\n", OutputType.Comment);
                    tempStt = trigHelper.GetInfoByFile(newDataSource.Value, newpathCs.Trigs, ref newDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + newpathCs.Trigs, JsonConvert.SerializeObject(newDbModels.Triggers.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (newDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取触发器\n", OutputType.Comment);
                    if (trigHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                    {
                        File.AppendAllText(resultStr + newpathCs.Trigs, JsonConvert.SerializeObject(newDbModels.Triggers.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                #endregion



                if (cs.IsDiff)
                {
                    trigHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);

                    if (string.IsNullOrEmpty(errorString) && tempBool)
                    {
                        AppendOutputText("对比完毕\n\n", OutputType.Comment);
                        File.AppendAllText(resultStr + diffpathCs.Trigs, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
                    }
                    else
                    {
                        //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                        //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                tempStr = RtxResult.Text;
            }



            if (cs.IsSearProc)
            {
                tempBool = true;
                ProcCompareAndShowResultHelper funcHelper = new ProcCompareAndShowResultHelper();
                funcHelper.OutputText          = AppendOutputText;
                funcHelper.ReplaceLastLineText = ReplaceLastLineText;


                #region 获取数据源

                if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取存储过程\n", OutputType.Comment);
                    tempStt = funcHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.Procs, ref oldDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Procs, JsonConvert.SerializeObject(oldDbModels.Procs.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (oldDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取存储过程\n", OutputType.Comment);
                    if (funcHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Procs, JsonConvert.SerializeObject(oldDbModels.Procs.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }
                if (newDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取存储过程\n", OutputType.Comment);
                    tempStt = funcHelper.GetInfoByFile(newDataSource.Value, newpathCs.Procs, ref newDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + newpathCs.Procs, JsonConvert.SerializeObject(newDbModels.Procs.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (newDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取存储过程\n", OutputType.Comment);
                    if (funcHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                    {
                        File.AppendAllText(resultStr + newpathCs.Procs, JsonConvert.SerializeObject(newDbModels.Procs.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                #endregion

                if (cs.IsDiff)
                {
                    funcHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);
                    //CompareAndShowResult(procs, newProcs, cs, out string errorString);

                    if (string.IsNullOrEmpty(errorString) && tempBool)
                    {
                        AppendOutputText("对比完毕\n\n", OutputType.Comment);
                        File.AppendAllText(resultStr + diffpathCs.Procs, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
                    }
                    else
                    {
                        //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                        //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                tempStr = RtxResult.Text;
            }



            if (cs.IsSearFunc)
            {
                tempBool = true;
                FuncCompareAndShowResultHelper funcHelper = new FuncCompareAndShowResultHelper();
                funcHelper.OutputText          = AppendOutputText;
                funcHelper.ReplaceLastLineText = ReplaceLastLineText;


                #region 获取数据源

                if (oldDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取函数\n", OutputType.Comment);
                    tempStt = funcHelper.GetInfoByFile(oldDataSource.Value, oldpathCs.Funcs, ref oldDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Funcs, JsonConvert.SerializeObject(oldDbModels.Functions.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (oldDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取函数\n", OutputType.Comment);
                    if (funcHelper.GetInfoByDb(oldDataSource.Value, ref oldDbModels))
                    {
                        File.AppendAllText(resultStr + oldpathCs.Funcs, JsonConvert.SerializeObject(oldDbModels.Functions.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                if (newDataSource.Type == DBDataSourceType.DataSourceFile)
                {
                    AppendOutputText("从文件中获取函数\n", OutputType.Comment);
                    tempStt = funcHelper.GetInfoByFile(newDataSource.Value, newpathCs.Funcs, ref newDbModels);
                    if (string.IsNullOrWhiteSpace(tempStt))
                    {
                        File.AppendAllText(resultStr + newpathCs.Funcs, JsonConvert.SerializeObject(newDbModels.Functions.Values));
                    }
                    else
                    {
                        tempBool = false;
                        AppendOutputText(tempStt + "\r\n", OutputType.Error);
                    }
                }
                else if (newDataSource.Type == DBDataSourceType.MySql)
                {
                    AppendOutputText("从数据库中获取函数\n", OutputType.Comment);
                    if (funcHelper.GetInfoByDb(newDataSource.Value, ref newDbModels))
                    {
                        File.AppendAllText(resultStr + newpathCs.Funcs, JsonConvert.SerializeObject(newDbModels.Functions.Values));
                    }
                    else
                    {
                        tempBool = false;
                    }
                }

                #endregion


                if (cs.IsDiff)
                {
                    funcHelper.CompareAndShow(ref oldDbModels, ref newDbModels, cs, out string errorString);

                    if (string.IsNullOrEmpty(errorString) && tempBool)
                    {
                        AppendOutputText("对比完毕\n\n", OutputType.Comment);
                        File.AppendAllText(resultStr + diffpathCs.Funcs, string.IsNullOrWhiteSpace(tempStr) ? RtxResult.Text : RtxResult.Text.Replace(tempStr, ""));
                    }
                    else
                    {
                        //string tips = string.Concat("对比中发现以下问题,请修正后重新进行比较:\n\n", errorString);
                        //MessageBox.Show(tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                tempStr = RtxResult.Text;
            }

            //bool compIsError = false;

            AppendOutputText("\n", OutputType.Comment);
            AppendOutputText("执行完毕\n", OutputType.Comment);

            SetStatus(false);
            //try
            //{
            //    AbortTh();
            //}
            //catch (Exception)
            //{
            //}
        }
Exemplo n.º 6
0
        public override bool GetInfoByDb(string connStr, ref DbModels rel)
        {
            List <Function> tempList;
            string          errorMsg;

            using (Helper = new DBStructureHelper(connStr))
            {
                Helper.Set_DbHander(SetLen);
                if (Helper.Open())
                {
                    OutputText("开始获取数据库函数结构(" + Helper.Server + (Helper.Port == "-1" ? "" : ":" + Helper.Port) + "  " + Helper.DbName + ")\n", OutputType.Comment);
                    bool   tempBool = true;
                    string spName2  = "";
                    if (isFun)
                    {
                        spName2  = "函数";
                        tempBool = Helper.GetFuncs(out tempList, out errorMsg);
                    }
                    else
                    {
                        spName2  = "存储过程";
                        tempBool = Helper.GetProcs(out tempList, out errorMsg);
                    }
                    if (tempBool)
                    {
                        OutputText("  获取到 " + tempList.Count + " 个" + spName2 + "\n", OutputType.Comment);
                        OutputText("...", OutputType.Comment);
                        if (isFun)
                        {
                            rel.Functions = new Dictionary <string, Function>();
                            foreach (var item in tempList)
                            {
                                item.Info = Helper.GetFuncInfo(item.Name);
                                rel.Functions.Add(item.Name, item);
                            }
                        }
                        else
                        {
                            rel.Procs = new Dictionary <string, Function>();
                            foreach (var item in tempList)
                            {
                                item.Info = Helper.GetProcInfo(item.Name);
                                rel.Procs.Add(item.Name, item);
                            }
                        }
                        OutputText("\n", OutputType.None);
                        OutputText("\n", OutputType.Comment);
                        return(true);
                    }
                    else
                    {
                        OutputText("获取" + spName2 + "信息失败:" + errorMsg, OutputType.Comment);
                        return(false);
                    }
                }
                else
                {
                    OutputText("打开数据库失败(" + Helper.DbName + ")", OutputType.Comment);
                    return(false);
                }
            }
        }
Exemplo n.º 7
0
        public override bool CompareAndShow(ref DbModels oldModel, ref DbModels newModel, Setting setting, out string errorString)
        {
            Dictionary <string, Function> oldItems = isFun? oldModel.Functions : oldModel.Procs;
            Dictionary <string, Function> newItems = isFun ? newModel.Functions : newModel.Procs;

            StringBuilder errorStringBuilder = new StringBuilder();
            string        temp = isFun ? "函数" : "存储过程";

            // 找出新版本中删除的表
            List <string> dropTableNames = new List <string>();

            foreach (string tableName in oldItems.Keys)
            {
                if (!newItems.Keys.Contains(tableName))
                {
                    dropTableNames.Add(tableName);
                }
            }
            //OutputText("\n", OutputType.None);
            //OutputText("\n", OutputType.None);
            if (dropTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中删除以下" + temp + ":{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中删除以下" + temp + ":{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                if (isFun)
                {
                    foreach (var viewName in dropTableNames)
                    {
                        string dropViewSql = dHelper.GetDropFuncSql(viewName);
                        //OutputText(dropViewSql, OutputType.Sql);
                        Output(dropViewSql, OutputType.Sql, setting, SqlType.Delete);
                    }
                }
                else
                {
                    foreach (var viewName in dropTableNames)
                    {
                        string dropViewSql = dHelper.GetDropProcsSql(viewName);
                        //OutputText(dropViewSql, OutputType.Sql);
                        Output(dropViewSql, OutputType.Sql, setting, SqlType.Delete);
                    }
                }
            }
            // 找出新版本中新增的表
            List <string> addTableNames = new List <string>();

            foreach (string tableName in newItems.Keys)
            {
                if (!oldItems.Keys.Contains(tableName))
                {
                    addTableNames.Add(tableName);
                }
            }
            if (addTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中新增以下" + temp + ":{0}\n", JoinString(addTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中新增以下" + temp + ":{0}\n", JoinString(addTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                if (isFun)
                {
                    foreach (var viewName in addTableNames)
                    {
                        //OutputText(string.Format("生成创建{0}{1}的SQL\n", viewName, temp), OutputType.Comment);
                        Output(string.Format("生成创建{0}{1}的SQL\n", viewName, temp), OutputType.Comment, setting, SqlType.Common);
                        string addViewSql = dHelper.GetAddFuncSql(newItems[viewName]);
                        AppendLine(addViewSql, OutputType.Sql);
                        //OutputText("\n", OutputType.None);
                        Output("\n", OutputType.None, setting, SqlType.Common);
                    }
                }
                else
                {
                    foreach (var viewName in addTableNames)
                    {
                        //OutputText(string.Format("生成创建{0}{1}的SQL\n", viewName, temp), OutputType.Comment);
                        Output(string.Format("生成创建{0}{1}的SQL\n", viewName, temp), OutputType.Comment, setting, SqlType.Common);
                        string addViewSql = dHelper.GetAddProcsSql(newItems[viewName]);
                        AppendLine(addViewSql, OutputType.Sql);
                        //OutputText("\n", OutputType.None);
                        Output("\n", OutputType.None, setting, SqlType.Common);
                    }
                }
            }
            // 对两版本中均存在的表格进行对比
            foreach (string tableName in newItems.Keys)
            {
                Function newTableInfo = newItems[tableName];
                if (oldItems.Keys.Contains(tableName))
                {
                    //AppendLine("----------------------------------------------\n", OutputType.Comment);
                    Output("----------------------------------------------\n", OutputType.Comment, setting, SqlType.Common);
                    //AppendLine(string.Format(temp + ":{0}\n", tableName), OutputType.Comment);
                    Output(string.Format(temp + ":{0}\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    Function oldTableInfo = oldItems[tableName];

                    if (setting.CheckCommon && !string.Equals(newTableInfo.Comment, oldTableInfo.Comment))
                    {
                        //AppendLine(string.Format("  注释:\"{0}\" => \"{1}\"\n", oldTableInfo.Comment, newTableInfo.Comment), OutputType.Comment);
                        Output(string.Format("  注释:\"{0}\" => \"{1}\"\n", oldTableInfo.Comment, newTableInfo.Comment), OutputType.Comment, setting, SqlType.Common);
                    }
                    // 对比表校对集
                    if (!newTableInfo.CharSet.Equals(oldTableInfo.CharSet))
                    {
                        //AppendLine(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment);
                        Output(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    if (!newTableInfo.ClientCharSet.Equals(oldTableInfo.ClientCharSet))
                    {
                        //AppendLine(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment);
                        Output(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    //if (!newTableInfo.Info.SQLModel.Equals(oldTableInfo.Info.SQLModel))
                    //{
                    //    AppendLine(string.Format("  SQLModel:\"{0}\" => \"{1}\"\n", oldTableInfo.Info.SQLModel, newTableInfo.Info.SQLModel), OutputType.Comment);
                    //}
                    //避免DEFINER 和注释产生影响
                    var flagTypeStr = isFun ? "FUNCTION" : "PROCEDURE";

                    string oldSql = oldTableInfo.Info.CreateSQL;
                    string newSql = newTableInfo.Info.CreateSQL;

                    if (oldSql.IndexOf("CREATE DEFINER=") > -1 && oldSql.IndexOf(flagTypeStr) > 0)
                    {
                        oldSql = "CREATE " + oldSql.Substring(oldSql.IndexOf(flagTypeStr));
                    }
                    if (newSql.IndexOf("CREATE DEFINER=") > -1 && newSql.IndexOf(flagTypeStr) > 0)
                    {
                        newSql = "CREATE " + newSql.Substring(newSql.IndexOf(flagTypeStr));
                    }

                    //忽略 CHARSET
                    int temp_int = oldSql.IndexOf(" CHARSET ");
                    if (temp_int > 0 && oldSql.IndexOf("begin") > temp_int)
                    {
                        oldSql = oldSql.Substring(0, temp_int) + "\r\n" + oldSql.Substring(oldSql.IndexOf("begin"));
                    }
                    temp_int = newSql.IndexOf(" CHARSET ");
                    if (temp_int > 0 && newSql.IndexOf("begin") > temp_int)
                    {
                        newSql = newSql.Substring(0, temp_int) + "\r\n" + newSql.Substring(newSql.IndexOf("begin"));
                    }

                    //忽略换行
                    oldSql = oldSql.Replace("\r\n", "").Replace("\n", "");
                    newSql = newSql.Replace("\r\n", "").Replace("\n", "");

                    //if (tableName == "fun_getMemberPropertyValue") {
                    //    int ooo = 0;
                    //}
                    if (!oldSql.Equals(newSql))
                    {
                        //AppendLine("  " + temp + "内容有变化\n", OutputType.Comment);
                        Output("  " + temp + "内容有变化\n", OutputType.Comment, setting, SqlType.Common);
                        //int inxItem = -1;
                        //foreach (char item in oldSql)
                        //{
                        //    inxItem++;
                        //    if (newSql.Length > inxItem)
                        //    {
                        //        if (newSql[inxItem] != oldSql[inxItem])
                        //        {
                        //            bool sqlNoEq = false;
                        //        }
                        //    }
                        //}
                        //删除后创建
                        if (isFun)
                        {
                            string dropViewSql = dHelper.GetDropFuncSql(tableName);
                            AppendLine(dropViewSql, OutputType.Sql);
                            //OutputText(string.Format("生成创建{0}{1}的SQL\n", tableName, temp), OutputType.Comment);
                            Output(string.Format("生成创建{0}{1}的SQL\n", tableName, temp), OutputType.Comment, setting, SqlType.Common);
                            string addViewSql = dHelper.GetAddFuncSql(newItems[tableName]);
                            AppendLine(addViewSql, OutputType.Sql);
                            //OutputText("\n", OutputType.None);
                            Output("\n", OutputType.None, setting, SqlType.Common);
                        }
                        else
                        {
                            string dropViewSql = dHelper.GetDropProcsSql(tableName);
                            AppendLine(dropViewSql, OutputType.Sql);
                            //OutputText(string.Format("生成创建{0}{1}的SQL\n", tableName, temp), OutputType.Comment);
                            Output(string.Format("生成创建{0}{1}的SQL\n", tableName, temp), OutputType.Comment, setting, SqlType.Common);
                            string addViewSql = dHelper.GetAddProcsSql(newItems[tableName]);
                            AppendLine(addViewSql, OutputType.Sql);
                            //OutputText("\n", OutputType.None);
                            Output("\n", OutputType.None, setting, SqlType.Common);
                        }
                    }
                }
            }

            AppendLineToCtrl(setting.OutputComment ? 3 : 1);
            errorString = errorStringBuilder.ToString();
            return(string.IsNullOrWhiteSpace(errorString));
        }
        public override bool CompareAndShow(ref DbModels oldModel, ref DbModels newModel, Setting setting, out string errorString)
        {
            Dictionary <string, ViewInfo> oldItems = oldModel.Views;
            Dictionary <string, ViewInfo> newItems = newModel.Views;



            StringBuilder errorStringBuilder = new StringBuilder();

            // 找出新版本中删除的表
            List <string> dropTableNames = new List <string>();

            foreach (string tableName in oldItems.Keys)
            {
                if (!newItems.Keys.Contains(tableName))
                {
                    dropTableNames.Add(tableName);
                }
            }
            //OutputText("\n", OutputType.None);
            //OutputText("\n", OutputType.None);
            if (dropTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中删除以下视图:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中删除以下视图:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                foreach (var viewName in dropTableNames)
                {
                    string dropViewSql = dHelper.GetDropViewSql(viewName);
                    //OutputText(dropViewSql, OutputType.Sql);
                    Output(dropViewSql, OutputType.Sql, setting, SqlType.Delete);
                }
            }
            // 找出新版本中新增的表
            List <string> addTableNames = new List <string>();

            foreach (string tableName in newItems.Keys)
            {
                if (!oldItems.Keys.Contains(tableName))
                {
                    addTableNames.Add(tableName);
                }
            }
            if (addTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中新增以下视图:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中新增以下视图:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                foreach (var viewName in addTableNames)
                {
                    //OutputText(string.Format("生成创建{0}视图的SQL\n", viewName), OutputType.Comment);
                    Output(string.Format("生成创建{0}视图的SQL\n", viewName), OutputType.Comment, setting, SqlType.Common);
                    string addViewSql = dHelper.GetAddViewSql(newItems[viewName].CreateSQL);
                    AppendLine(addViewSql, OutputType.Sql);
                    //OutputText("\n", OutputType.None);
                    Output("\n", OutputType.None, setting, SqlType.Common);
                }
            }
            // 对两版本中均存在的表格进行对比
            foreach (string tableName in newItems.Keys)
            {
                if (oldItems.Keys.Contains(tableName))
                {
                    //AppendLine("----------------------------------------------\n", OutputType.Comment);
                    Output("----------------------------------------------\n", OutputType.Comment, setting, SqlType.Common);
                    //AppendLine(string.Format("视图:{0}\n", tableName), OutputType.Comment);
                    Output(string.Format("视图:{0}\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    ViewInfo newTableInfo = newItems[tableName];
                    ViewInfo oldTableInfo = oldItems[tableName];


                    // 对比表校对集
                    if (!newTableInfo.CharSet.Equals(oldTableInfo.CharSet))
                    {
                        //AppendLine(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment);
                        Output(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    if (!newTableInfo.ClientCharSet.Equals(oldTableInfo.ClientCharSet))
                    {
                        //AppendLine(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment);
                        Output(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    //避免DEFINER 和注释产生影响
                    string oldSql = oldTableInfo.CreateSQL; //.Substring(oldTableInfo.CreateSQL.IndexOf("`" + oldTableInfo.Name + "`"));
                    string newSql = newTableInfo.CreateSQL; //.Substring(oldTableInfo.CreateSQL.IndexOf("`" + newTableInfo.Name + "`"));


                    string flagTypeStr = "VIEW";

                    //忽略DEFINER 以及 SQL SECURITY
                    if (oldSql.IndexOf("CREATE ") > -1 && oldSql.IndexOf(" DEFINER=") > -1 && oldSql.IndexOf(flagTypeStr) > 0)
                    {
                        oldSql = "CREATE " + oldSql.Substring(oldSql.IndexOf(flagTypeStr));
                    }
                    if (newSql.IndexOf("CREATE ") > -1 && newSql.IndexOf(" DEFINER=") > -1 && newSql.IndexOf(flagTypeStr) > 0)
                    {
                        newSql = "CREATE " + newSql.Substring(newSql.IndexOf(flagTypeStr));
                    }

                    if (!oldSql.Equals(newSql))
                    {
                        //AppendLine("  内容有变化\n", OutputType.Comment);
                        Output("  内容有变化\n", OutputType.Comment, setting, SqlType.Common);
                        //OutputText(string.Format("生成创建{0}视图的SQL\n", tableName), OutputType.Comment);
                        Output(string.Format("生成修改{0}视图的SQL\n", tableName), OutputType.Comment, setting, SqlType.Common);
                        string addViewSql = dHelper.GetEditViewSql(newItems[tableName].CreateSQL);
                        AppendLine(addViewSql, OutputType.Sql);
                    }
                }
            }

            AppendLineToCtrl(setting.OutputComment ? 3 : 1);
            errorString = errorStringBuilder.ToString();
            return(string.IsNullOrWhiteSpace(errorString));
        }
        public override bool CompareAndShow(ref DbModels oldModel, ref DbModels newModel, Setting setting, out string errorString)
        {
            Dictionary <string, Trigger> oldItems = oldModel.Triggers;
            Dictionary <string, Trigger> newItems = newModel.Triggers;


            StringBuilder errorStringBuilder = new StringBuilder();

            // 找出新版本中删除的表
            List <string> dropTableNames = new List <string>();

            foreach (string tableName in oldItems.Keys)
            {
                if (!newItems.Keys.Contains(tableName))
                {
                    dropTableNames.Add(tableName);
                }
            }
            //OutputText("\n", OutputType.None);
            //OutputText("\n", OutputType.None);
            if (dropTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中删除以下触发器:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中删除以下触发器:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                foreach (var viewName in dropTableNames)
                {
                    string dropViewSql = dHelper.GetDropTrisSql(viewName);
                    //OutputText(dropViewSql, OutputType.Sql);
                    Output(dropViewSql, OutputType.Sql, setting, SqlType.Delete);
                }
            }
            // 找出新版本中新增的表
            List <string> addTableNames = new List <string>();

            foreach (string tableName in newItems.Keys)
            {
                if (!oldItems.Keys.Contains(tableName))
                {
                    addTableNames.Add(tableName);
                }
            }
            if (addTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中新增以下触发器:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中新增以下触发器:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                foreach (var viewName in addTableNames)
                {
                    //OutputText(string.Format("生成创建{0}触发器的SQL\n", viewName), OutputType.Comment);
                    Output(string.Format("生成创建{0}触发器的SQL\n", viewName), OutputType.Comment, setting, SqlType.Common);
                    string addViewSql = dHelper.GetAddTrisSql(newItems[viewName]);
                    AppendLine(addViewSql, OutputType.Sql);
                    //OutputText("\n", OutputType.None);
                    Output("\n", OutputType.None, setting, SqlType.Common);
                }
            }
            // 对两版本中均存在的表格进行对比
            foreach (string tableName in newItems.Keys)
            {
                if (oldItems.Keys.Contains(tableName))
                {
                    //AppendLine("----------------------------------------------\n", OutputType.Comment);
                    Output("----------------------------------------------\n", OutputType.Comment, setting, SqlType.Common);
                    //AppendLine(string.Format("触发器:{0}\n", tableName), OutputType.Comment);
                    Output(string.Format("触发器:{0}\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    Trigger newTableInfo = newItems[tableName];
                    Trigger oldTableInfo = oldItems[tableName];

                    // 对比表校对集
                    if (!newTableInfo.CharSet.Equals(oldTableInfo.CharSet))
                    {
                        //AppendLine(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment);
                        Output(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.CharSet, newTableInfo.CharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    if (!newTableInfo.ClientCharSet.Equals(oldTableInfo.ClientCharSet))
                    {
                        //AppendLine(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment);
                        Output(string.Format("  校对集(Client):\"{0}\" => \"{1}\"\n", oldTableInfo.ClientCharSet, newTableInfo.ClientCharSet), OutputType.Comment, setting, SqlType.Common);
                    }
                    //if (!newTableInfo.SQLMode.Equals(oldTableInfo.SQLMode))
                    //{
                    //    AppendLine(string.Format("  SQLModel:\"{0}\" => \"{1}\"\n", oldTableInfo.SQLMode, newTableInfo.SQLMode), OutputType.Comment);
                    //}
                    //避免DEFINER 和注释产生影响
                    string oldSql = oldTableInfo.Statement;
                    string newSql = newTableInfo.Statement;
                    if (!oldSql.Equals(newSql))
                    {
                        //AppendLine("  触发器内容有变化\n", OutputType.Comment);
                        Output("  触发器内容有变化\n", OutputType.Comment, setting, SqlType.Common);
                        string dropViewSql = dHelper.GetDropTrisSql(tableName);
                        AppendLine(dropViewSql, OutputType.Sql);
                        //OutputText(string.Format("生成创建{0}触发器的SQL\n", tableName), OutputType.Comment);
                        Output(string.Format("生成创建{0}触发器的SQL\n", tableName), OutputType.Comment, setting, SqlType.Common);
                        string addViewSql = dHelper.GetAddTrisSql(newItems[tableName]);
                        AppendLine(addViewSql, OutputType.Sql);
                        //OutputText("\n", OutputType.None);
                        Output("\n", OutputType.None, setting, SqlType.Common);
                    }
                }
            }

            AppendLineToCtrl(setting.OutputComment ? 3 : 1);
            errorString = errorStringBuilder.ToString();
            return(string.IsNullOrWhiteSpace(errorString));
        }
Exemplo n.º 10
0
 public abstract bool CompareAndShow(ref DbModels oldItems, ref DbModels newItems, Setting setting, out string errorString);
Exemplo n.º 11
0
 public abstract string GetInfoByFile(string dirName, string fileName, ref DbModels list);
Exemplo n.º 12
0
 public abstract bool GetInfoByDb(string connStr, ref DbModels rel);
Exemplo n.º 13
0
        public override bool CompareAndShow(ref DbModels oldModel, ref DbModels newModel, Setting setting, out string errorString)
        {

            Dictionary<string, TableInfo> oldItems = oldModel.Tables;
            Dictionary<string, TableInfo> newItems = newModel.Tables;

            StringBuilder errorStringBuilder = new StringBuilder();

            // 找出新版本中删除的表
            List<string> dropTableNames = new List<string>();
            foreach (string tableName in oldItems.Keys)
            {
                if (!newItems.Keys.Contains(tableName))
                    dropTableNames.Add(tableName);
            }
            if (dropTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中删除以下表格:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中删除以下表格:{0}\n", JoinString(dropTableNames, ",")), OutputType.Comment, setting, SqlType.Common);
                foreach (string tableName in dropTableNames)
                {
                    //OutputText(string.Format("生成删除{0}表的SQL\n", tableName), OutputType.Comment);
                    Output(string.Format("生成删除{0}表的SQL\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    string dropTableSql = dHelper.GetDropTableSql( tableName);
                    //OutputText(dropTableSql, OutputType.Sql);
                    Output(dropTableSql, OutputType.Sql, setting, SqlType.Delete);
                    //OutputText("\n", OutputType.None);
                    Output("\n", OutputType.None, setting, SqlType.Common);
                }
            }
            // 找出新版本中新增的表
            List<string> addTableNames = new List<string>();
            foreach (string tableName in newItems.Keys)
            {
                if (!oldItems.Keys.Contains(tableName))
                    addTableNames.Add(tableName);
            }
            if (addTableNames.Count > 0)
            {
                //OutputText("==============================================\n", OutputType.Comment);
                Output("==============================================\n", OutputType.Comment, setting, SqlType.Common);
                //OutputText(string.Format("新版本数据库中新增以下表格:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment);
                Output(string.Format("新版本数据库中新增以下表格:{0}\n", JoinString(addTableNames, ",")), OutputType.Comment, setting, SqlType.Common);

                foreach (string tableName in addTableNames)
                {
                    //OutputText(string.Format("生成创建{0}表的SQL\n", tableName), OutputType.Comment);
                    Output(string.Format("生成创建{0}表的SQL\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    // 通过MySQL提供的功能得到建表SQL
                    var tabInfo = newItems[tableName];
                    string createTableSql = tabInfo.CreateSql;
                    AppendLine(createTableSql, OutputType.Sql);
                    //OutputText("\n", OutputType.None);
                    Output("\n", OutputType.None, setting, SqlType.Common);
                }

            }
            // 对两版本中均存在的表格进行对比
            foreach (string tableName in newItems.Keys)
            {
                if (oldItems.Keys.Contains(tableName))
                {
                    //if (tableName == "able_deliverynote") {
                    //    int i = 0;
                    //}
                    //AppendLine("----------------------------------------------\n", OutputType.Comment);
                    Output("----------------------------------------------\n", OutputType.Comment, setting, SqlType.Common);
                    //AppendLine(string.Format("表:{0}\n", tableName), OutputType.Comment);
                    Output(string.Format("表:{0}\n", tableName), OutputType.Comment, setting, SqlType.Common);
                    TableInfo newTableInfo = newItems[tableName];
                    TableInfo oldTableInfo = oldItems[tableName];

                    // 进行表结构比较

                    // 找出删除列
                    List<string> dropColumnNames = new List<string>();
                    foreach (string columnName in oldTableInfo.AllColumnInfo.Keys)
                    {
                        if (!newTableInfo.AllColumnInfo.ContainsKey(columnName))
                            dropColumnNames.Add(columnName);
                    }
                    if (dropColumnNames.Count > 0)
                    {
                        //AppendLine(string.Format("  新版本中删除以下列:{0}\n", JoinString(dropColumnNames, ",")), OutputType.Comment);
                        Output(string.Format("  新版本中删除以下列:{0}\n", JoinString(dropColumnNames, ",")), OutputType.Comment, setting, SqlType.Common);
                        foreach (string columnName in dropColumnNames)
                        {
                            string dropColumnSql = dHelper.GetDropTableColumnSql(tableName, columnName);
                            //AppendLine(dropColumnSql, OutputType.Sql);
                            Output(dropColumnSql, OutputType.Sql, setting, SqlType.Delete);
                        }
                    }



                    // 找出新增列
                    List<string> addColumnNames = new List<string>();
                    foreach (string columnName in newTableInfo.AllColumnInfo.Keys)
                    {
                        if (!oldTableInfo.AllColumnInfo.ContainsKey(columnName))
                            addColumnNames.Add(columnName);
                    }
                    List<string> oldCols = oldTableInfo.TableNames;
                    List<string> newCols = newTableInfo.TableNames;
                    foreach (var item in dropColumnNames)
                        if (oldCols.Contains(item))
                            oldCols.Remove(item);
                    foreach (var item in addColumnNames)
                        if (!oldCols.Contains(item))
                            oldCols.Add(item);
                    FieldSortedOption<string> fieldSortedOption = new FieldSortedOption<string>();
                    fieldSortedOption.NewList = newCols;
                    fieldSortedOption.OldList = oldCols;

                    var sortingOption = new SortingOption<string>();
                    sortingOption.GetSortedOption(ref fieldSortedOption);
                    List<string> sortFielded = new List<string>();
                    SortedOption<string> tempSort;
                    if (addColumnNames.Count > 0)
                    {
                        //AppendLine(string.Format("  新版本中新增以下列:{0}\n", JoinString(addColumnNames, ",")), OutputType.Comment);
                        Output(string.Format("  新版本中新增以下列:{0}\n", JoinString(addColumnNames, ",")), OutputType.Comment, setting, SqlType.Common);
                        foreach (string columnName in addColumnNames)
                        {
                            bool isChecked = sortingOption.IsChecked(columnName, out tempSort);
                            string offset = null;
                            string fieldName = null;
                            if (isChecked)
                            {
                                sortFielded.Add(columnName);
                                offset = tempSort.OptionType.ToString();
                                fieldName = tempSort.NewValue;
                            }
                            string addColumnSql = dHelper.GetAddTableColumnSql(tableName, newTableInfo.AllColumnInfo[columnName], offset, fieldName);
                            AppendLine(addColumnSql, OutputType.Sql);
                        }

                    }
                    // 找出列属性修改
                    foreach (string columnName in newTableInfo.AllColumnInfo.Keys)
                    {
                        if (oldTableInfo.AllColumnInfo.ContainsKey(columnName))
                        {
                            ColumnInfo newColumnInfo = newTableInfo.AllColumnInfo[columnName];
                            ColumnInfo oldColumnInfo = oldTableInfo.AllColumnInfo[columnName];
                            // 比较各个属性
                            bool isDataTypeSame = newColumnInfo.DataType.Equals(oldColumnInfo.DataType);
                            bool isCommentSame = newColumnInfo.Comment.Equals(oldColumnInfo.Comment);
                            if (!setting.CheckCommon) isCommentSame = true;
                            bool isNotEmptySame = newColumnInfo.IsNotEmpty == oldColumnInfo.IsNotEmpty;
                            bool isAutoIncrementSame = newColumnInfo.IsAutoIncrement == oldColumnInfo.IsAutoIncrement;
                            bool isDefaultValueSame = newColumnInfo.DefaultValue.Equals(oldColumnInfo.DefaultValue);
                            if (isDataTypeSame == false || isCommentSame == false || isNotEmptySame == false || isAutoIncrementSame == false || isDefaultValueSame == false)
                            {
                                //AppendLine(string.Format("  列:{0}\n", columnName), OutputType.Comment);
                                Output(string.Format("  列:{0}\n", columnName), OutputType.Comment, setting, SqlType.Common);
                                if (isDataTypeSame == false)
                                    //AppendLine(string.Format("    属性:数据类型{0} => {1}\n", oldColumnInfo.DataType, newColumnInfo.DataType), OutputType.Comment);
                                    Output(string.Format("    属性:数据类型{0} => {1}\n", oldColumnInfo.DataType, newColumnInfo.DataType), OutputType.Comment, setting, SqlType.Common);
                                if (isCommentSame == false)
                                    //AppendLine(string.Format("    属性:列注释\"{0}\" => \"{1}\"\n", oldColumnInfo.Comment, newColumnInfo.Comment), OutputType.Comment);
                                    Output(string.Format("    属性:列注释\"{0}\" => \"{1}\"\n", oldColumnInfo.Comment, newColumnInfo.Comment), OutputType.Comment, setting, SqlType.Common);
                                if (isNotEmptySame == false)
                                    //AppendLine(string.Format("    属性:(为空){0} => {1}\n", oldColumnInfo.IsNotEmpty == true ? "不允许" : "允许", newColumnInfo.IsNotEmpty == true ? "不允许" : "允许"), OutputType.Comment);
                                    Output(string.Format("    属性:(为空){0} => {1}\n", oldColumnInfo.IsNotEmpty == true ? "不允许" : "允许", newColumnInfo.IsNotEmpty == true ? "不允许" : "允许"), OutputType.Comment, setting, SqlType.Common);
                                if (isAutoIncrementSame == false)
                                    //AppendLine(string.Format("    属性:列设{0}  =>  {1}\n", oldColumnInfo.IsAutoIncrement == true ? "自增" : "不自增", newColumnInfo.IsAutoIncrement == true ? "自增" : "不自增"), OutputType.Comment);
                                    Output(string.Format("    属性:列设{0}  =>  {1}\n", oldColumnInfo.IsAutoIncrement == true ? "自增" : "不自增", newColumnInfo.IsAutoIncrement == true ? "自增" : "不自增"), OutputType.Comment, setting, SqlType.Common);
                                if (isDefaultValueSame == false)
                                    //AppendLine(string.Format("    属性:默认值{0}  =>  {1}\n", oldColumnInfo.DefaultValue, newColumnInfo.DefaultValue), OutputType.Comment);
                                    Output(string.Format("    属性:默认值{0}  =>  {1}\n", oldColumnInfo.DefaultValue, newColumnInfo.DefaultValue), OutputType.Comment, setting, SqlType.Common);

                                bool isChecked = sortingOption.IsChecked(columnName, out tempSort);
                                string offset = null;
                                string fieldName = null;
                                if (isChecked)
                                {
                                    sortFielded.Add(columnName);
                                    offset = tempSort.OptionType.ToString();
                                    fieldName = tempSort.NewValue;
                                }
                                // 根据新的列属性进行修改
                                string changeColumnSql = dHelper.GetChangeTableColumnSql(tableName, newColumnInfo, offset, fieldName);
                                AppendLine(changeColumnSql, OutputType.Sql);
                            }
                        }
                    }
                    if ( fieldSortedOption.Checked)
                    {
                        var sss = fieldSortedOption.Options.Where(i => !sortFielded.Contains(i.OptionValue) && i.OptionType != SortedOptionType.NONE);
                        if (sss.Any())
                        {
                            //AppendLine("  新版本数据库字段顺序改变\n", OutputType.Comment);
                            Output("  新版本数据库字段顺序改变\n", OutputType.Comment, setting, SqlType.Common);
                        }
                        foreach (var item in sss)
                        {
                            string sortFieldSql = dHelper.GetModifySort(tableName, newTableInfo.AllColumnInfo[item.OptionValue], item.OptionType.ToString(), item.NewValue);
                            AppendLine(sortFieldSql, OutputType.Sql);
                        }
                    }

                    //新增列后再修改顺序



                    // 在改变列属性前需先同步索引设置,因为自增属性仅可用于设置了索引的列
                    // 找出主键修改
                    bool isPrimaryKeySame = newTableInfo.PrimaryKeyColumnNames.Count == oldTableInfo.PrimaryKeyColumnNames.Count && newTableInfo.PrimaryKeyColumnNames.Any(i => oldTableInfo.PrimaryKeyColumnNames.Contains(i));
                    //isPrimaryKeySame &= newTableInfo.PrimaryKeyColumnNames.Count > 0 || oldTableInfo.PrimaryKeyColumnNames.Count > 0;

                    if (isPrimaryKeySame == false && (newTableInfo.PrimaryKeyColumnNames.Count > 0 || oldTableInfo.PrimaryKeyColumnNames.Count > 0))
                    {
                        string newPrimaryKeyString = newTableInfo.PrimaryKeyColumnNames.Count > 0 ? JoinString(newTableInfo.PrimaryKeyColumnNames, ",") : "无";
                        string oldPrimaryKeyString = oldTableInfo.PrimaryKeyColumnNames.Count > 0 ? JoinString(oldTableInfo.PrimaryKeyColumnNames, ",") : "无";
                        //AppendLine(string.Format("  主键:{0} => {1}\n", oldPrimaryKeyString, newPrimaryKeyString), OutputType.Comment);
                        Output(string.Format("  主键:{0} => {1}\n", oldPrimaryKeyString, newPrimaryKeyString), OutputType.Comment, setting, SqlType.Common);
                        // 先删除原有的主键设置
                        string dropPrimaryKeySql = dHelper.GetDropPrimarySql(tableName);
                        //AppendLine(dropPrimaryKeySql, OutputType.Sql);
                        Output(dropPrimaryKeySql, OutputType.Sql, setting, SqlType.Delete);

                        if (newTableInfo.PrimaryKeyColumnNames.Any())
                        {
                            // 再重新设置
                            string addPrimaryKeySql = dHelper.GetAddPrimarySql(tableName, newTableInfo.PrimaryKeyColumnNames);
                            AppendLine(addPrimaryKeySql, OutputType.Sql);
                        }
                    }

                    // 找出唯一索引修改
                    // 找出新版本中删除的索引
                    List<string> dropIndexNames = new List<string>();
                    foreach (string name in oldTableInfo.IndexInfo.Keys)
                    {
                        if (!newTableInfo.IndexInfo.ContainsKey(name))
                            dropIndexNames.Add(name);
                    }
                    if (dropIndexNames.Count > 0)
                    {
                        //AppendLine(string.Format("  新版本中删除以下索引:{0}\n", JoinString(dropIndexNames, ",")), OutputType.Comment);
                        Output(string.Format("  新版本中删除以下索引:{0}\n", JoinString(dropIndexNames, ",")), OutputType.Comment, setting, SqlType.Common);
                        foreach (string name in dropIndexNames)
                        {
                            string dropIndexSql = dHelper.GetDropIndexSql(tableName, name);
                            //AppendLine(dropIndexSql, OutputType.Sql);
                            Output(dropIndexSql, OutputType.Sql, setting, SqlType.Delete);
                        }
                    }
                    // 找出新版本中新增索引
                    List<TableIndex> addIndexNames = new List<TableIndex>();
                    foreach (string name in newTableInfo.IndexInfo.Keys)
                    {
                        if (!oldTableInfo.IndexInfo.ContainsKey(name))
                            addIndexNames.Add(newTableInfo.IndexInfo[name]);
                    }
                    if (addIndexNames.Count > 0)
                    {
                        //AppendLine(string.Format("  新版本中新增以下索引:{0}\n", JoinString(addIndexNames.Select(i => i.Name).ToList(), ",")), OutputType.Comment);
                        Output(string.Format("  新版本中新增以下索引:{0}\n", JoinString(addIndexNames.Select(i => i.Name).ToList(), ",")), OutputType.Comment, setting, SqlType.Common);
                        foreach (TableIndex tabInx in addIndexNames)
                        {
                            string addIndexSql = dHelper.GetAddIndexSql(tableName, tabInx);
                            AppendLine(addIndexSql, OutputType.Sql);
                        }
                    }
                    // 找出同名索引的变动
                    foreach (var pair in newTableInfo.IndexInfo)
                    {
                        string name = pair.Key;
                        if (oldTableInfo.IndexInfo.ContainsKey(name))
                        {
                            TableIndex newIndex = pair.Value;
                            TableIndex oldIndex = oldTableInfo.IndexInfo[name];

                            bool isIndexColumnSame = newIndex.Columns.Count == oldIndex.Columns.Count && newIndex.Columns.Any(i => oldIndex.Columns.Contains(i));
                            bool isIndexComment = (newIndex.Common ?? "") == (oldIndex.Common ?? "");

                            if (isIndexColumnSame == false || newIndex.IndexFunc != oldIndex.IndexFunc ||
                                newIndex.IndexType != oldIndex.IndexType || isIndexComment == false)
                            {
                                //AppendLine(string.Format("  名为{0}的索引:\n", name), OutputType.Comment);
                                Output(string.Format("  名为{0}的索引:\n", name), OutputType.Comment, setting, SqlType.Common);
                                if (isIndexColumnSame == false)
                                    //AppendLine(string.Format("    涉及列名:{0} => {1}\n", JoinString(oldIndex.Columns, ","), JoinString(newIndex.Columns, ",")), OutputType.Comment);
                                    Output(string.Format("    涉及列名:{0} => {1}\n", JoinString(oldIndex.Columns, ","), JoinString(newIndex.Columns, ",")), OutputType.Comment, setting, SqlType.Common);
                                if (newIndex.IndexFunc != oldIndex.IndexFunc)
                                    //AppendLine(string.Format("    索引方法:{0} => {1}\n", oldIndex.IndexFunc + "", newIndex.IndexFunc + ""), OutputType.Comment);
                                    Output(string.Format("    索引方法:{0} => {1}\n", oldIndex.IndexFunc + "", newIndex.IndexFunc + ""), OutputType.Comment, setting, SqlType.Common);
                                if (newIndex.IndexType != oldIndex.IndexType)
                                    //AppendLine(string.Format("    索引类型:{0} => {1}\n", oldIndex.IndexType + "", newIndex.IndexType + ""), OutputType.Comment);
                                    Output(string.Format("    索引类型:{0} => {1}\n", oldIndex.IndexType + "", newIndex.IndexType + ""), OutputType.Comment, setting, SqlType.Common);
                                if (setting.CheckCommon && isIndexComment == false)
                                    //AppendLine(string.Format("    注释:{0} => {1}\n", oldIndex.Common, newIndex.Common), OutputType.Comment);
                                    Output(string.Format("    注释:{0} => {1}\n", oldIndex.Common, newIndex.Common), OutputType.Comment, setting, SqlType.Common);
                                // 先删除
                                string dropIndexSql = dHelper.GetDropIndexSql(tableName, name);
                                AppendLine(dropIndexSql, OutputType.Sql);
                                // 再重新创建
                                string addIndexSql = dHelper.GetAddIndexSql(tableName, newIndex);
                                AppendLine(addIndexSql, OutputType.Sql);
                            }
                        }
                    }


                    // 对比表校对集
                    if (!newTableInfo.Collation.Equals(oldTableInfo.Collation))
                    {
                        //AppendLine(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.Collation, newTableInfo.Collation), OutputType.Comment);
                        Output(string.Format("  校对集:\"{0}\" => \"{1}\"\n", oldTableInfo.Collation, newTableInfo.Collation), OutputType.Comment, setting, SqlType.Common);
                        string alterTableComment = dHelper.GetChangeCollateSql(tableName, newTableInfo.Collation);
                        AppendLine(alterTableComment, OutputType.Sql);
                    }

                    // 对比表注释
                    if (setting.CheckCommon && !newTableInfo.Comment.Equals(oldTableInfo.Comment))
                    {
                        //AppendLine(string.Format("  注释:\"{0}\" => \"{1}\"\n", oldTableInfo.Comment, newTableInfo.Comment), OutputType.Comment);
                        Output(string.Format("  注释:\"{0}\" => \"{1}\"\n", oldTableInfo.Comment, newTableInfo.Comment), OutputType.Comment, setting, SqlType.Common);
                        string alterTableComment = dHelper.GetChangeCommentSql(tableName, newTableInfo.Comment);
                        AppendLine(alterTableComment, OutputType.Sql);
                    }


                    // 对比表选项
                    string alterTableOption;

                    bool isDiffTableOption = false;
                    if (isDiffTableOption)
                    {
                        if (oldTableInfo.Option.Auto_Increment != newTableInfo.Option.Auto_Increment)
                        {
                            //AppendLine(string.Format("  自动增加:{0} => {1}\n", oldTableInfo.Option.Auto_Increment, newTableInfo.Option.Auto_Increment), OutputType.Comment);
                            Output(string.Format("  自动增加:{0} => {1}\n", oldTableInfo.Option.Auto_Increment, newTableInfo.Option.Auto_Increment), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Auto_Increment), newTableInfo.Option.Auto_Increment);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.Avg_Row_Length != newTableInfo.Option.Avg_Row_Length)
                        {
                            //AppendLine(string.Format("  平均记录长度:{0} => {1}\n", oldTableInfo.Option.Avg_Row_Length, newTableInfo.Option.Avg_Row_Length), OutputType.Comment);
                            Output(string.Format("  平均记录长度:{0} => {1}\n", oldTableInfo.Option.Avg_Row_Length, newTableInfo.Option.Avg_Row_Length), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Avg_Row_Length), newTableInfo.Option.Avg_Row_Length);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.Checksum != newTableInfo.Option.Checksum)
                        {
                            //AppendLine(string.Format("  检查记录和:{0} => {1}\n", oldTableInfo.Option.Checksum, newTableInfo.Option.Checksum), OutputType.Comment);
                            Output(string.Format("  检查记录和:{0} => {1}\n", oldTableInfo.Option.Checksum, newTableInfo.Option.Checksum), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Checksum), newTableInfo.Option.Checksum);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.COMPRESSION != newTableInfo.Option.COMPRESSION)
                        {
                            //AppendLine(string.Format("  压缩方式:{0} => {1}\n", oldTableInfo.Option.COMPRESSION, newTableInfo.Option.COMPRESSION), OutputType.Comment);
                            Output(string.Format("  压缩方式:{0} => {1}\n", oldTableInfo.Option.COMPRESSION, newTableInfo.Option.COMPRESSION), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.COMPRESSION), newTableInfo.Option.COMPRESSION);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.ENCRYPTION != newTableInfo.Option.ENCRYPTION)
                        {
                            //AppendLine(string.Format("  加密:{0} => {1}\n", oldTableInfo.Option.ENCRYPTION, newTableInfo.Option.ENCRYPTION), OutputType.Comment);
                            Output(string.Format("  加密:{0} => {1}\n", oldTableInfo.Option.ENCRYPTION, newTableInfo.Option.ENCRYPTION), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.ENCRYPTION), newTableInfo.Option.ENCRYPTION);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.Engine != newTableInfo.Option.Engine)
                        {
                            //AppendLine(string.Format("  引擎:{0} => {1}\n", oldTableInfo.Option.Engine, newTableInfo.Option.Engine), OutputType.Comment);
                            Output(string.Format("  引擎:{0} => {1}\n", oldTableInfo.Option.Engine, newTableInfo.Option.Engine), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Engine), newTableInfo.Option.Engine);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.Max_Rows != newTableInfo.Option.Max_Rows)
                        {
                            //AppendLine(string.Format("  最大记录行数:{0} => {1}\n", oldTableInfo.Option.Max_Rows, newTableInfo.Option.Max_Rows), OutputType.Comment);
                            Output(string.Format("  最大记录行数:{0} => {1}\n", oldTableInfo.Option.Max_Rows, newTableInfo.Option.Max_Rows), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Max_Rows), newTableInfo.Option.Max_Rows);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.Min_Rows != newTableInfo.Option.Min_Rows)
                        {
                            //AppendLine(string.Format("  最小记录行数:{0} => {1}\n", oldTableInfo.Option.Min_Rows, newTableInfo.Option.Min_Rows), OutputType.Comment);
                            Output(string.Format("  最小记录行数:{0} => {1}\n", oldTableInfo.Option.Min_Rows, newTableInfo.Option.Min_Rows), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.Min_Rows), newTableInfo.Option.Min_Rows);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.RowFormat != newTableInfo.Option.RowFormat)
                        {
                            //AppendLine(string.Format("  记录格式:{0} => {1}\n", oldTableInfo.Option.RowFormat, newTableInfo.Option.RowFormat), OutputType.Comment);
                            Output(string.Format("  记录格式:{0} => {1}\n", oldTableInfo.Option.RowFormat, newTableInfo.Option.RowFormat), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.RowFormat), newTableInfo.Option.RowFormat);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.STATS_AUTO_RECALC != newTableInfo.Option.STATS_AUTO_RECALC)
                        {
                            //AppendLine(string.Format("  累计数据自动重计:{0} => {1}\n", oldTableInfo.Option.STATS_AUTO_RECALC, newTableInfo.Option.STATS_AUTO_RECALC), OutputType.Comment);
                            Output(string.Format("  累计数据自动重计:{0} => {1}\n", oldTableInfo.Option.STATS_AUTO_RECALC, newTableInfo.Option.STATS_AUTO_RECALC), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.STATS_AUTO_RECALC), newTableInfo.Option.STATS_AUTO_RECALC);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.STATS_PERSISTENT != newTableInfo.Option.STATS_PERSISTENT)
                        {
                            //AppendLine(string.Format("  统计数据持久:{0} => {1}\n", oldTableInfo.Option.STATS_PERSISTENT, newTableInfo.Option.STATS_PERSISTENT), OutputType.Comment);
                            Output(string.Format("  统计数据持久:{0} => {1}\n", oldTableInfo.Option.STATS_PERSISTENT, newTableInfo.Option.STATS_PERSISTENT), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.STATS_PERSISTENT), newTableInfo.Option.STATS_PERSISTENT);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                        if (oldTableInfo.Option.TABLESPACE != newTableInfo.Option.TABLESPACE)
                        {
                            //AppendLine(string.Format("  表空间:{0} => {1}\n", oldTableInfo.Option.TABLESPACE, newTableInfo.Option.TABLESPACE), OutputType.Comment);
                            Output(string.Format("  表空间:{0} => {1}\n", oldTableInfo.Option.TABLESPACE, newTableInfo.Option.TABLESPACE), OutputType.Comment, setting, SqlType.Common);
                            alterTableOption = dHelper.GetChangeOptionSql(tableName, nameof(newTableInfo.Option.TABLESPACE), newTableInfo.Option.TABLESPACE);
                            AppendLine(alterTableOption, OutputType.Sql);
                        }

                    }



                    //if (DeleteLastLintText("表:"))
                    //    DeleteLastLintText("----------------------------------------------");
                }
            }
            AppendLineToCtrl(setting.OutputComment ? 3 : 1);

            errorString = errorStringBuilder.ToString();
            return string.IsNullOrWhiteSpace(errorString);
        }