public static DbInterpreter GetDbInterpreter(DatabaseType dbType, ConnectionInfo connectionInfo, DbInterpreterOption option)
        {
            DbInterpreter dbInterpreter = null;

            if(dbType == DatabaseType.SqlServer)
            {
                dbInterpreter = new SqlServerInterpreter(connectionInfo, option);
            }
            else if(dbType == DatabaseType.MySql)
            {
                dbInterpreter = new MySqlInterpreter(connectionInfo, option);
            }
            else if(dbType == DatabaseType.Oracle)
            {
                dbInterpreter = new OracleInterpreter(connectionInfo, option);
            }           

            return dbInterpreter;
        }
        public override ScriptBuilder GenerateSchemaScripts(SchemaInfo schemaInfo)
        {
            ScriptBuilder    sb = new ScriptBuilder();
            MySqlInterpreter mySqlInterpreter        = this.dbInterpreter as MySqlInterpreter;
            string           dbCharSet               = mySqlInterpreter.DbCharset;
            string           notCreateIfExistsClause = mySqlInterpreter.NotCreateIfExistsClause;

            #region Function
            sb.AppendRange(this.GenerateScriptDbObjectScripts <Function>(schemaInfo.Functions));
            #endregion

            #region Create Table
            foreach (Table table in schemaInfo.Tables)
            {
                this.FeedbackInfo(OperationState.Begin, table);

                string tableName       = table.Name;
                string quotedTableName = this.GetQuotedObjectName(table);

                IEnumerable <TableColumn> tableColumns = schemaInfo.TableColumns.Where(item => item.TableName == tableName).OrderBy(item => item.Order);

                IEnumerable <TablePrimaryKey> primaryKeys = schemaInfo.TablePrimaryKeys.Where(item => item.TableName == tableName);
                IEnumerable <TableForeignKey> foreignKeys = schemaInfo.TableForeignKeys.Where(item => item.TableName == tableName);
                IEnumerable <TableIndex>      indexes     = schemaInfo.TableIndexes.Where(item => item.TableName == tableName).OrderBy(item => item.Order);

                this.RestrictColumnLength(tableColumns, primaryKeys.SelectMany(item => item.Columns));
                this.RestrictColumnLength(tableColumns, foreignKeys.SelectMany(item => item.Columns));
                this.RestrictColumnLength(tableColumns, indexes.SelectMany(item => item.Columns));

                string primaryKeyColumns = "";

                if (this.option.TableScriptsGenerateOption.GeneratePrimaryKey && primaryKeys.Count() > 0)
                {
                    TablePrimaryKey primaryKey = primaryKeys.FirstOrDefault();

                    primaryKeyColumns =
                        $@"
,PRIMARY KEY
(
{string.Join(Environment.NewLine, primaryKey.Columns.Select(item => $"{ this.GetQuotedString(item.ColumnName)},")).TrimEnd(',')}
)";
                }

                #region Table

                string tableScript =
                    $@"
CREATE TABLE {notCreateIfExistsClause} {quotedTableName}(
{string.Join("," + Environment.NewLine, tableColumns.Select(item => this.dbInterpreter.ParseColumn(table, item)))}{primaryKeyColumns}
){(!string.IsNullOrEmpty(table.Comment) ? ($"comment='{this.dbInterpreter.ReplaceSplitChar(ValueHelper.TransferSingleQuotation(table.Comment))}'") : "")}
DEFAULT CHARSET={dbCharSet}" + this.scriptsDelimiter;

                sb.AppendLine(new CreateDbObjectScript <Table>(tableScript));

                #endregion

                //#region Primary Key
                //if (this.option.TableScriptsGenerateOption.GeneratePrimaryKey && primaryKeys.Count() > 0)
                //{
                //    TablePrimaryKey primaryKey = primaryKeys.FirstOrDefault();

                //    if (primaryKey != null)
                //    {
                //        sb.AppendLine(this.AddPrimaryKey(primaryKey));
                //    }
                //}
                //#endregion

                List <string> foreignKeysLines = new List <string>();

                #region Foreign Key
                if (this.option.TableScriptsGenerateOption.GenerateForeignKey)
                {
                    foreach (TableForeignKey foreignKey in foreignKeys)
                    {
                        sb.AppendLine(this.AddForeignKey(foreignKey));
                    }
                }

                #endregion

                #region Index
                if (this.option.TableScriptsGenerateOption.GenerateIndex)
                {
                    foreach (TableIndex index in indexes)
                    {
                        sb.AppendLine(this.AddIndex(index));
                    }
                }
                #endregion

                sb.AppendLine();

                this.FeedbackInfo(OperationState.End, table);
            }
            #endregion

            #region View
            sb.AppendRange(this.GenerateScriptDbObjectScripts <View>(schemaInfo.Views));

            #endregion

            #region Trigger
            sb.AppendRange(this.GenerateScriptDbObjectScripts <TableTrigger>(schemaInfo.TableTriggers));
            #endregion

            #region Procedure
            sb.AppendRange(this.GenerateScriptDbObjectScripts <Procedure>(schemaInfo.Procedures));
            #endregion

            if (this.option.ScriptOutputMode.HasFlag(GenerateScriptOutputMode.WriteToFile))
            {
                this.AppendScriptsToFile(sb.ToString(), GenerateScriptMode.Schema, true);
            }

            return(sb);
        }
        public override ScriptBuilder AddTable(Table table, IEnumerable <TableColumn> columns,
                                               TablePrimaryKey primaryKey,
                                               IEnumerable <TableForeignKey> foreignKeys,
                                               IEnumerable <TableIndex> indexes,
                                               IEnumerable <TableConstraint> constraints)
        {
            ScriptBuilder sb = new ScriptBuilder();

            MySqlInterpreter mySqlInterpreter        = this.dbInterpreter as MySqlInterpreter;
            string           dbCharSet               = mySqlInterpreter.DbCharset;
            string           notCreateIfExistsClause = mySqlInterpreter.NotCreateIfExistsClause;

            string tableName       = table.Name;
            string quotedTableName = this.GetQuotedObjectName(table);

            this.RestrictColumnLength(columns, primaryKey?.Columns);
            this.RestrictColumnLength(columns, foreignKeys.SelectMany(item => item.Columns));
            this.RestrictColumnLength(columns, indexes.SelectMany(item => item.Columns));

            string primaryKeyColumns = "";

            if (this.option.TableScriptsGenerateOption.GeneratePrimaryKey && primaryKey != null)
            {
                primaryKeyColumns =
                    $@"
,PRIMARY KEY
(
{string.Join(Environment.NewLine, primaryKey.Columns.Select(item => $"{ this.GetQuotedString(item.ColumnName)},")).TrimEnd(',')}
)";
            }

            #region Table

            string tableScript =
                $@"
CREATE TABLE {notCreateIfExistsClause} {quotedTableName}(
{string.Join("," + Environment.NewLine, columns.Select(item => this.dbInterpreter.ParseColumn(table, item)))}{primaryKeyColumns}
){(!string.IsNullOrEmpty(table.Comment) ? ($"comment='{this.dbInterpreter.ReplaceSplitChar(ValueHelper.TransferSingleQuotation(table.Comment))}'") : "")}
DEFAULT CHARSET={dbCharSet}" + this.scriptsDelimiter;

            sb.AppendLine(new CreateDbObjectScript <Table>(tableScript));

            #endregion

            //#region Primary Key
            //if (this.option.TableScriptsGenerateOption.GeneratePrimaryKey && primaryKeys.Count() > 0)
            //{
            //    TablePrimaryKey primaryKey = primaryKeys.FirstOrDefault();

            //    if (primaryKey != null)
            //    {
            //        sb.AppendLine(this.AddPrimaryKey(primaryKey));
            //    }
            //}
            //#endregion

            List <string> foreignKeysLines = new List <string>();

            #region Foreign Key
            if (this.option.TableScriptsGenerateOption.GenerateForeignKey)
            {
                foreach (TableForeignKey foreignKey in foreignKeys)
                {
                    sb.AppendLine(this.AddForeignKey(foreignKey));
                }
            }

            #endregion

            #region Index
            if (this.option.TableScriptsGenerateOption.GenerateIndex)
            {
                foreach (TableIndex index in indexes)
                {
                    sb.AppendLine(this.AddIndex(index));
                }
            }
            #endregion

            sb.AppendLine();

            return(sb);
        }