Ejemplo n.º 1
0
        private string CreateProcedureCommandScriptText(Func <MySqlCommand> BuildCommand, string procName)
        {
            bool alreadyOpened = connection.State == ConnectionState.Open;

            try
            {
                if (!alreadyOpened)
                {
                    connection.Open();
                }

                var str1 = $"Command {procName} for table {tableName.FullQuotedString}";
                var str  = CreateProcedureCommandText(BuildCommand(), procName);
                return(MySqlBuilder.WrapScriptTextWithComments(str, str1));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error during CreateProcedureCommand : {ex}");
                throw;
            }
            finally
            {
                if (!alreadyOpened && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public MySqlObjectNames(DmTable tableDescription)
        {
            this.TableDescription     = tableDescription;
            (tableName, trackingName) = MySqlBuilder.GetParsers(this.TableDescription);

            SetDefaultNames();
        }
Ejemplo n.º 3
0
        public string ScriptAddFilterColumn(DmColumn filterColumn)
        {
            var quotedColumnName = ParserName.Parse(filterColumn, "`").Quoted().ToString();

            string str = string.Concat("Add new filter column, ", quotedColumnName, ", to Tracking Table ", trackingName.Quoted().ToString());

            return(MySqlBuilder.WrapScriptTextWithComments(this.AddFilterColumnCommandText(filterColumn), str));
        }
Ejemplo n.º 4
0
 public MySqlBuilderTrackingTable(DmTable tableDescription, DbConnection connection, DbTransaction transaction = null)
 {
     this.connection       = connection as MySqlConnection;
     this.transaction      = transaction as MySqlTransaction;
     this.tableDescription = tableDescription;
     (this.tableName, this.trackingName) = MySqlBuilder.GetParsers(this.tableDescription);
     this.mySqlDbMetadata = new MySqlDbMetadata();
 }
Ejemplo n.º 5
0
        public string DropTableScriptText()
        {
            var commandText = $"drop table if exists {this.tableName.Quoted().ToString()}";

            var str1 = $"Drop table {this.tableName.Quoted().ToString()}";

            return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1));
        }
Ejemplo n.º 6
0
 public MySqlBuilderTrigger(DmTable tableDescription, DbConnection connection, DbTransaction transaction = null)
 {
     this.connection       = connection as MySqlConnection;
     this.transaction      = transaction as MySqlTransaction;
     this.tableDescription = tableDescription;
     (this.tableName, this.trackingName) = MySqlBuilder.GetParsers(this.tableDescription);
     this.mySqlObjectNames = new MySqlObjectNames(this.tableDescription);
 }
Ejemplo n.º 7
0
        public string ScriptAddFilterColumn(DmColumn filterColumn)
        {
            var quotedColumnName = new ObjectNameParser(filterColumn.ColumnName, "`", "`");

            string str = string.Concat("Add new filter column, ", quotedColumnName.FullUnquotedString, ", to Tracking Table ", trackingName.FullQuotedString);

            return(MySqlBuilder.WrapScriptTextWithComments(this.AddFilterColumnCommandText(filterColumn), str));
        }
Ejemplo n.º 8
0
        public string DropTableScriptText()
        {
            var commandText = $"drop table if exists {trackingName.FullQuotedString}";

            var str1 = $"Drop table {trackingName.FullQuotedString}";

            return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1));
        }
Ejemplo n.º 9
0
        private string DropProcedureText(DbCommandType procType)
        {
            var commandName = this.sqlObjectNames.GetCommandName(procType);
            var commandText = $"drop procedure if exists {commandName}";

            var str1 = $"Drop procedure {commandName} for table {tableName.FullQuotedString}";

            return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1));
        }
Ejemplo n.º 10
0
        private string DropTriggerText(DbCommandType triggerType)
        {
            var commandName = this.mySqlObjectNames.GetCommandName(triggerType).name;
            var commandText = $"drop trigger if exists {commandName}";

            var str1 = $"Drop trigger {commandName} for table {tableName.Quoted().ToString()}";

            return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1));
        }
Ejemplo n.º 11
0
        public string CreateTableScriptText()
        {
            StringBuilder stringBuilder   = new StringBuilder();
            var           tableNameScript = $"Create Table {tableName.QuotedString}";
            var           tableScript     = BuildTableCommand().CommandText;

            stringBuilder.Append(MySqlBuilder.WrapScriptTextWithComments(tableScript, tableNameScript));
            stringBuilder.AppendLine();
            return(stringBuilder.ToString());
        }
Ejemplo n.º 12
0
        public string CreateForeignKeyConstraintsScriptText(DmRelation constraint)
        {
            StringBuilder stringBuilder = new StringBuilder();

            var constraintName   = $"Create Constraint {constraint.RelationName} between parent {constraint.ParentTable.TableName.ToLowerInvariant()} and child {constraint.ChildTable.TableName.ToLowerInvariant()}";
            var constraintScript = BuildForeignKeyConstraintsCommand(constraint).CommandText;

            stringBuilder.Append(MySqlBuilder.WrapScriptTextWithComments(constraintScript, constraintName));
            stringBuilder.AppendLine();

            return(stringBuilder.ToString());
        }
Ejemplo n.º 13
0
        public string CreateInsertTriggerScriptText()
        {
            var           insTriggerName = string.Format(this.mySqlObjectNames.GetCommandName(DbCommandType.InsertTrigger), tableName.ObjectNameNormalized);
            StringBuilder createTrigger  = new StringBuilder();

            createTrigger.AppendLine($"CREATE TRIGGER {insTriggerName} AFTER INSERT ON {tableName.FullQuotedString} FOR EACH ROW ");
            createTrigger.AppendLine();
            createTrigger.AppendLine(this.InsertTriggerBodyText());

            string str = $"Insert Trigger for table {tableName.FullQuotedString}";

            return(MySqlBuilder.WrapScriptTextWithComments(createTrigger.ToString(), str));
        }
Ejemplo n.º 14
0
        public string CreateUpdateTriggerScriptText()
        {
            var           updTriggerName = string.Format(this.mySqlObjectNames.GetCommandName(DbCommandType.UpdateTrigger).name, tableName.Unquoted().Normalized().ToString());
            StringBuilder createTrigger  = new StringBuilder();

            createTrigger.AppendLine($"CREATE TRIGGER {updTriggerName} AFTER UPDATE ON {tableName.Quoted().ToString()} FOR EACH ROW ");
            createTrigger.AppendLine();
            createTrigger.AppendLine(this.UpdateTriggerBodyText());

            string str = $"Update Trigger for table {tableName.Quoted().ToString()}";

            return(MySqlBuilder.WrapScriptTextWithComments(createTrigger.ToString(), str));
        }
Ejemplo n.º 15
0
        public string CreateDeleteTriggerScriptText()
        {
            var           delTriggerName = string.Format(this.sqliteObjectNames.GetCommandName(DbCommandType.DeleteTrigger), tableName.UnquotedStringWithUnderScore);
            StringBuilder createTrigger  = new StringBuilder();

            createTrigger.AppendLine($"CREATE TRIGGER {delTriggerName} AFTER DELETE ON {tableName.QuotedString} FOR EACH ROW ");
            createTrigger.AppendLine();
            createTrigger.AppendLine(this.DeleteTriggerBodyText());

            string str = $"Delete Trigger for table {tableName.QuotedString}";

            return(MySqlBuilder.WrapScriptTextWithComments(createTrigger.ToString(), str));
        }
Ejemplo n.º 16
0
        public string CreatePopulateFromBaseTableScriptText()
        {
            string str = string.Concat("Populate tracking table ", trackingName.FullQuotedString, " for existing data in table ", tableName.FullQuotedString);

            return(MySqlBuilder.WrapScriptTextWithComments(this.CreatePopulateFromBaseTableCommandText(), str));
        }
Ejemplo n.º 17
0
        public string CreateTableScriptText()
        {
            string str = string.Concat("Create Tracking Table ", trackingName.FullQuotedString);

            return(MySqlBuilder.WrapScriptTextWithComments(this.CreateTableCommandText(), str));
        }