Example #1
0
        public override void LoadDatabase(IDatabaseSource dst)
        {
            var             sconn = PostgreSettings.CheckPostgreSource(dst);
            PostgreSettings cfg   = GlobalSettings.Pages.PageByName("postgre_client") as PostgreSettings;

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

            pars.AppendFormat("-U {0} ", sconn.Login);
            pars.AppendFormat("--host={0} ", sconn.DataSource);
            pars.AppendFormat("--dbname={0} ", dst.DatabaseName ?? sconn.ExplicitDatabaseName);
            p.StartInfo.EnvironmentVariables["PGPASSWORD"] = sconn.Password;
            if (sconn.Port > 0)
            {
                pars.AppendFormat("--port={0} ", sconn.Port);
            }
            pars.AppendFormat("-f {0} ", Filename);

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

            thr.Start();
            p.WaitForExit();
            thr.Join();
        }
Example #2
0
        //bool m_useClientTools = true;

        //[XmlElem]
        //[Category("SQL")]
        //[DatAdmin.DisplayName("s_use_client_tools")]
        //[TypeConverter(typeof(YesNoTypeConverter))]
        //public bool UseClientTools
        //{
        //    get { return m_useClientTools; }
        //    set
        //    {
        //        if (!value && Registration.SoftwareEdition < SoftwareEdition.Professional)
        //        {
        //            Logging.Warning("Edition error: Postgre set use client tools");
        //            throw new BadEditionError(SoftwareEdition.Professional);
        //        }
        //        m_useClientTools = value;
        //    }
        //}

        public override void RunDirectCopy(IDatabaseSource source, DatabaseCopyOptions copyOpts)
        {
            var             sconn = PostgreSettings.CheckPostgreSource(source);
            PostgreSettings cfg   = GlobalSettings.Pages.PageByName("postgre_client") as PostgreSettings;

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

            pars.AppendFormat("-U {0} ", sconn.Login);
            pars.AppendFormat("--host={0} ", sconn.DataSource);
            p.StartInfo.EnvironmentVariables["PGPASSWORD"] = sconn.Password;
            if (sconn.Port > 0)
            {
                pars.AppendFormat("--port={0} ", sconn.Port);
            }
            if (IncludeDropStatement)
            {
                pars.Append("--clean ");
            }
            pars.Append("--verbose ");
            pars.AppendFormat("\"--file={0}\" ", GetWorkingFileName());

            pars.Append(source.DatabaseName ?? sconn.ExplicitDatabaseName);

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

            thr.Start();
            p.WaitForExit();
            thr.Join();
            FinalizeFileName();
        }