示例#1
0
        private string GetTableOptionSql(bool newTable)
        {
            List <string> options = new List <string>();
            StringBuilder sql     = new StringBuilder(" ");

            if (!newTable)
            {
                if (Name != OldTable.Name)
                {
                    options.Add(string.Format("RENAME TO `{0}` ", Name));
                }
            }
            if (AutoInc != OldTable.AutoInc)
            {
                options.Add(string.Format("AUTO_INCREMENT={0}", AutoInc));
            }
            if (AvgRowLength != OldTable.AvgRowLength)
            {
                options.Add(string.Format("AVG_ROW_LENGTH={0}", AvgRowLength));
            }
            if (CheckSum != OldTable.CheckSum)
            {
                options.Add(string.Format("CHECKSUM={0}", CheckSum ? 1 : 0));
            }
            if (Engine != OldTable.Engine)
            {
                options.Add(string.Format("ENGINE={0}", Engine));
            }
            if (InsertMethod != OldTable.InsertMethod)
            {
                options.Add(string.Format("INSERT_METHOD={0}", InsertMethod.ToString()));
            }
            if (MaxRows != OldTable.MaxRows)
            {
                options.Add(string.Format("MAX_ROWS={0}", MaxRows));
            }
            if (MinRows != OldTable.MinRows)
            {
                options.Add(string.Format("MIN_ROWS={0}", MinRows));
            }
            if (PackKeys != OldTable.PackKeys)
            {
                options.Add(string.Format("PACK_KEYS={0}", PackKeys.ToString()));
            }
            if (RowFormat != OldTable.RowFormat)
            {
                options.Add(string.Format("ROW_FORMAT={0}", RowFormat.ToString()));
            }
            if (StringPropertyHasChanged(Comment, OldTable.Comment))
            {
                options.Add(string.Format("COMMENT='{0}'", Comment));
            }
            if (StringPropertyHasChanged(CharacterSet, OldTable.CharacterSet))
            {
                options.Add(string.IsNullOrEmpty(CharacterSet) ? "DEFAULT CHARACTER SET" :
                            string.Format("CHARACTER SET='{0}'", CharacterSet));
            }
            if (StringPropertyHasChanged(Collation, OldTable.Collation))
            {
                options.Add(string.IsNullOrEmpty(Collation) ? "DEFAULT COLLATE" :
                            string.Format("COLLATE='{0}'", Collation));
            }
            if (StringPropertyHasChanged(DataDirectory, OldTable.DataDirectory))
            {
                options.Add(string.Format("DATA DIRECTORY='{0}' ", DataDirectory));
            }
            if (StringPropertyHasChanged(IndexDirectory, OldTable.IndexDirectory))
            {
                options.Add(string.Format("INDEX DIRECTORY='{0}' ", IndexDirectory));
            }

            string delimiter = "";

            foreach (string option in options)
            {
                sql.AppendFormat("{0}{1}", delimiter, option);
                delimiter = ",\r\n";
            }
            return(sql.ToString());
        }