Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to make the backup compatible with the MySql Workbench import? #73

Open
DennisRodriguez opened this issue Apr 19, 2021 · 2 comments

Comments

@DennisRodriguez
Copy link

Additionally, There is a problem in Excluding a table. The table was excluded but not the trigger associated with it.
Since you already have a collection of excluded tables can't you use it to filter the triggers?
.i.e
Show Triggers Where `Table` not in ('tabmename','tablename');

As for the issue with importing the backup to Work Bench. This is the same for Procedures, Functions, Triggers and Events.
What you can do is double the delimiter before the routine name and after the END statement. Something like.

DELIMITER ;;
CREATE PROCEDURE MyProcedure()
BEGIN
END ;;

Export_WriteLine("DELIMITER " + ExportInfo.ScriptsDelimiter+ExportInfo.ScriptsDelimiter);

if (ExportInfo.ExportRoutinesWithoutDefiner)
    Export_WriteLine(trigger.CreateTriggerSQLWithoutDefiner + " " + ExportInfo.ScriptsDelimiter + ExportInfo.ScriptsDelimiter);
else
    Export_WriteLine(trigger.CreateTriggerSQL + " " + ExportInfo.ScriptsDelimiter + ExportInfo.ScriptsDelimiter);

Export_WriteLine("DELIMITER " + ExportInfo.ScriptsDelimiter);

With the above code I have successfully imported a backup without an error in Workbench Version 8.0.23 with MySql Server Version 5.7.33.

Thanks,
Dennis
@DennisRodriguez
Copy link
Author

Or as a temporary and faster solution. You can add the table name in your MySqlTrigger i.e.

public class MySqlTrigger
{
    string _tablename = "";
    string _name = "";
    string _createTriggerSQL = "";
    string _createTriggerSQLWithoutDefiner = "";

    public string TableName  { get { return _tablename; } }
    public string Name { get { return _name; } }
    public string CreateTriggerSQL { get { return _createTriggerSQL; } }
    public string CreateTriggerSQLWithoutDefiner { get { return _createTriggerSQLWithoutDefiner; } }

    public MySqlTrigger(MySqlCommand cmd, string triggerName, string definer, string tablename)
    {
         _name = triggerName;
         _tablename = tablename;

And in your MySqlTriggerList Class

public MySqlTriggerList(MySqlCommand cmd)
{
    _sqlShowTriggers = "SHOW TRIGGERS;";

    try
    {
        DataTable dt = QueryExpress.GetTable(cmd, _sqlShowTriggers);

        foreach (DataRow dr in dt.Rows)
        {
            _lst.Add(new MySqlTrigger(cmd, dr["Trigger"] + "", dr["Definer"] + "", dr["Table"] + ""));
        }
    }
    catch (MySqlException myEx)
    {
        if (myEx.Message.ToLower().Contains("access denied"))
            _allowAccess = false;
    }
    catch
    {
        throw;
    }
}

Then in your MySqlBackup Class

if (trigger.CreateTriggerSQL.Trim().Length == 0 ||
   trigger.CreateTriggerSQLWithoutDefiner.Trim().Length == 0 || 
   Export_ThisTableIsExcluded(trigger.TableName))
   continue;

Although I still believe passing the Excluded tables object to your MyTriggerList Class would be better, but I don't think the above approach would make a noticeable performance issue.

Thanks
Dennis

@adriancs2
Copy link
Member

Hi, @DennisRodriguez , thanks for the information provided. I will look into this issue in few days and I'll try to come out with a solution. thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants