示例#1
0
        public string GenerateSchemaScripts(SchemaInfo schemaInfo)
        {
            SelectionInfo selectionInfo = new SelectionInfo()
            {
                TableNames = schemaInfo.Tables.Select(item => item.Name).ToArray()
            };

            return(Interpreter.GenerateSchemaScripts(Interpreter.GetSchemaInfo(selectionInfo, false)));
        }
示例#2
0
        private void SourceScriptBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (this.sourceScriptBackgroundWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            SchemaInfo schemaInfo = this.GetSourceTreeSchemaInfo();

            if (!this.ValidateSource(schemaInfo))
            {
                return;
            }

            DatabaseType sourceDbType = this.GetDatabaseType(this.cboSourceDB.Text);

            int dataBatchSize = SettingManager.Setting.DataBatchSize;
            GenerateScriptOption sourceScriptOption = new GenerateScriptOption()
            {
                ScriptOutputMode = GenerateScriptOutputMode.None, DataBatchSize = dataBatchSize
            };

            this.SetGenerateScriptOption(sourceScriptOption);

            GenerateScriptMode scriptMode = this.GetGenerateScriptMode();

            if (scriptMode == GenerateScriptMode.None)
            {
                MessageBox.Show("Please specify the script mode.");
                return;
            }

            DbInterpreter dbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, this.sourceDbConnectionInfo, sourceScriptOption);

            string[] tableNames = schemaInfo.Tables.Select(item => item.Name).ToArray();
            schemaInfo = dbInterpreter.GetSchemaInfo(tableNames);

            dbInterpreter.Subscribe(this);

            if (scriptMode.HasFlag(GenerateScriptMode.Schema))
            {
                dbInterpreter.GenerateSchemaScripts(schemaInfo);
            }

            if (scriptMode.HasFlag(GenerateScriptMode.Data))
            {
                dbInterpreter.GenerateDataScripts(schemaInfo);
            }

            MessageBox.Show(DONE);
        }
示例#3
0
        private async void GenerateScourceDbScripts()
        {
            SchemaInfo schemaInfo = this.GetSourceTreeSchemaInfo();

            if (!this.ValidateSource(schemaInfo))
            {
                return;
            }

            this.btnGenerateSourceScripts.Enabled = false;

            DatabaseType sourceDbType = this.GetDatabaseType(this.cboSourceDB.Text);

            int dataBatchSize = SettingManager.Setting.DataBatchSize;
            DbInterpreterOption sourceScriptOption = new DbInterpreterOption()
            {
                ScriptOutputMode = GenerateScriptOutputMode.WriteToFile, DataBatchSize = dataBatchSize
            };

            this.SetGenerateScriptOption(sourceScriptOption);

            GenerateScriptMode scriptMode = this.GetGenerateScriptMode();

            if (scriptMode == GenerateScriptMode.None)
            {
                MessageBox.Show("Please specify the script mode.");
                return;
            }

            DbInterpreter dbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, this.sourceDbConnectionInfo, sourceScriptOption);

            SelectionInfo selectionInfo = new SelectionInfo()
            {
                UserDefinedTypeNames = schemaInfo.UserDefinedTypes.Select(item => item.Name).ToArray(),
                TableNames           = schemaInfo.Tables.Select(item => item.Name).ToArray(),
                ViewNames            = schemaInfo.Views.Select(item => item.Name).ToArray()
            };

            try
            {
                schemaInfo = await dbInterpreter.GetSchemaInfoAsync(selectionInfo);

                dbInterpreter.Subscribe(this);

                GenerateScriptMode mode = GenerateScriptMode.None;

                if (scriptMode.HasFlag(GenerateScriptMode.Schema))
                {
                    mode = GenerateScriptMode.Schema;
                    dbInterpreter.GenerateSchemaScripts(schemaInfo);
                }

                if (scriptMode.HasFlag(GenerateScriptMode.Data))
                {
                    mode = GenerateScriptMode.Data;
                    await dbInterpreter.GenerateDataScriptsAsync(schemaInfo);
                }

                this.OpenInExplorer(dbInterpreter.GetScriptOutputFilePath(mode));

                MessageBox.Show(DONE);
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
            }

            this.btnGenerateSourceScripts.Enabled = true;
        }
示例#4
0
        public string GenerateSchemaScripts(params string[] tableNames)
        {
            SchemaInfo schemaInfo = Interpreter.GetSchemaInfo(tableNames);

            return(Interpreter.GenerateSchemaScripts(schemaInfo));
        }