Beispiel #1
0
        public override void LoadDatabase(IDatabaseSource dst)
        {
            MySqlStoredConnection sconn = MySqlSettings.CheckMySqlSource(dst);
            MySqlSettings         cfg   = GlobalSettings.Pages.PageByName("mysql_client") as MySqlSettings;

            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = cfg.GetToolPath("mysql");
            StringBuilder pars = new StringBuilder();

            pars.AppendFormat("--user={0} ", sconn.Login);
            pars.AppendFormat("--password={0} ", sconn.Password);
            pars.AppendFormat("--host={0} ", sconn.DataSource);
            pars.AppendFormat("--port={0} ", sconn.Port);

            pars.Append("--verbose ");
            pars.Append(dst.DatabaseName ?? sconn.ExplicitDatabaseName);
            pars.Append(" ");

            p.StartInfo.Arguments             = pars.ToString();
            p.StartInfo.UseShellExecute       = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardError = true;
            Logging.Debug("Running mysql " + pars.ToString());
            p.Start();
            Thread thr = new Thread(() => ReadFromErrStream(p));

            thr.Start();
            using (FileStream fr = new FileInfo(Filename).OpenRead())
            {
                IOTool.CopyStream(fr, p.StandardInput.BaseStream);
            }
            p.StandardInput.Close();
            p.WaitForExit();
            thr.Join();
        }
Beispiel #2
0
        public override void RunDirectCopy(IDatabaseSource source, DatabaseCopyOptions copyOpts)
        {
            MySqlStoredConnection sconn = MySqlSettings.CheckMySqlSource(source);
            MySqlSettings         cfg   = GlobalSettings.Pages.PageByName("mysql_client") as MySqlSettings;

            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = cfg.GetToolPath("mysqldump");
            StringBuilder pars = new StringBuilder();

            pars.AppendFormat("--user={0} ", sconn.Login);
            pars.AppendFormat("--password={0} ", sconn.Password);
            pars.AppendFormat("--host={0} ", sconn.DataSource);
            pars.AppendFormat("--port={0} ", sconn.Port);
            pars.Append("--routines ");
            if (IncludeDropStatement)
            {
                pars.Append("--add-drop-table ");
            }
            else
            {
                pars.Append("--skip-add-drop-table ");
            }

            pars.Append("--verbose ");
            pars.Append(source.DatabaseName ?? sconn.ExplicitDatabaseName);
            pars.Append(" ");

            if (copyOpts.CopyMembers.TableFilter != null)
            {
                pars.Append("--tables ");
                foreach (NameWithSchema table in copyOpts.CopyMembers.TableFilter)
                {
                    pars.Append(table.Name + " ");
                }
            }

            p.StartInfo.Arguments              = pars.ToString();
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            Logging.Debug("Running mysqldump " + pars.ToString());
            p.Start();
            Thread thr = new Thread(() => ReadFromErrStream(p));

            thr.Start();
            //Console.Write(p.StandardOutput.ReadToEnd());
            using (FileStream fw = new FileStream(GetWorkingFileName(), FileMode.Create))
            {
                IOTool.CopyStream(p.StandardOutput.BaseStream, fw);
            }
            p.WaitForExit();
            thr.Join();
            FinalizeFileName();
        }