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 GenerateSql(IDatabaseSource db, FullDatabaseRelatedName objname, ISqlDumper dmp, ISqlDialect dialect)
        {
            var ts = db.InvokeLoadTableStructure(objname.ObjectName, TableStructureMembers.ConstraintsNoRefs);
            var cs = ts.FindConstraint(objname.ObjectType, objname.SubName);

            DoGenerateSql(dmp, ts, cs);
        }
Beispiel #3
0
        public void GenerateDropAllTables(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            DatabaseStructureMembers dbmem = new DatabaseStructureMembers
            {
                TableList           = true,
                TableMembers        = TableStructureMembers.ForeignKeys,
                IgnoreSystemObjects = true,
            };
            var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);
            foreach (ITableStructure tbl in dbs.Tables)
            {
                if (conn.Dialect.IsSystemTable(tbl.FullName))
                {
                    continue;
                }
                foreach (IForeignKey fk in tbl.GetConstraints <IForeignKey>())
                {
                    dmp.DropConstraint(fk);
                }
            }
            foreach (ITableStructure tbl in dbs.Tables)
            {
                if (conn.Dialect.IsSystemTable(tbl.FullName))
                {
                    continue;
                }
                dmp.DropTable(tbl, DropFlags.None);
            }
        }
Beispiel #4
0
 public CopyTableForm(ITableSource src, IDatabaseSource dst)
 {
     InitializeComponent();
     cbcopydata.Enabled = src.TableCaps.DataStoreForReading && dst.TableCaps.DataStoreForWriting;
     tbltblname.Text    = src.FullName.Name;
     cbcopydata_CheckedChanged(this, EventArgs.Empty);
 }
Beispiel #5
0
        public GridTable GetGridData(IDatabaseSource sourcedb, IDatabaseSource targetdb, SynTableData data, bool denyLoad)
        {
            if (m_grids[(int)data] == null && !denyLoad)
            {
                m_gridSourceConn = sourcedb;
                m_gridTargetConn = targetdb;

                switch (data)
                {
                case SynTableData.OnlyInSource:
                    m_gridFills[(int)data] = new GridTable(m_srcInfo.GetTableStructure(SynQueryType.SelectAll), sourcedb.ToString());
                    break;

                case SynTableData.OnlyInTarget:
                    m_gridFills[(int)data] = new GridTable(m_dstInfo.GetTableStructure(SynQueryType.SelectAll), targetdb.ToString());
                    break;

                case SynTableData.Equal:
                    m_gridFills[(int)data] = new GridTable(m_srcInfo.GetTableStructure(SynQueryType.SelectAll), sourcedb.ToString());
                    break;

                case SynTableData.Modified:
                    var ts = new TableStructure();
                    m_srcInfo.FillKey(ts);
                    m_srcInfo.FillDataColumns(ts);
                    m_dstInfo.FillDataColumns(ts);

                    for (int i = 0; i < m_srcInfo.KeyCols.Length; i++)
                    {
                        var col = (ColumnStructure)ts.Columns[i];
                        col.ColumnName = "K-" + col.ColumnName;
                    }
                    for (int i = 0; i < m_srcInfo.DataCols.Length; i++)
                    {
                        var col = (ColumnStructure)ts.Columns[i + m_srcInfo.KeyCols.Length];
                        col.ColumnName = "1-" + col.ColumnName;
                    }
                    for (int i = 0; i < m_dstInfo.DataCols.Length; i++)
                    {
                        var col = (ColumnStructure)ts.Columns[i + m_srcInfo.KeyCols.Length + m_srcInfo.DataCols.Length];
                        col.ColumnName = "2-" + col.ColumnName;
                    }

                    m_gridFills[(int)data] = new GridTable(ts, sourcedb.ToString());
                    break;
                }
                try
                {
                    ProcessFootprints();
                    m_grids[(int)data] = m_gridFills[(int)data];
                }
                finally
                {
                    m_gridFills[(int)data] = null;
                    m_gridSourceConn       = null;
                    m_gridTargetConn       = null;
                }
            }
            return(m_grids[(int)data]);
        }
Beispiel #6
0
        public static List <IAbstractObjectStructure> GetStructureList_NonEffective(this IDatabaseSource db, Func <IDatabaseStructure, IEnumerable> extractCollection)
        {
            List <IAbstractObjectStructure> res = new List <IAbstractObjectStructure>();
            IDatabaseStructure dbs;

            if (db.Connection == null)
            {
                dbs = db.LoadDatabaseStructure(DatabaseStructureMembers.FullStructure, null);
            }
            else
            {
                dbs = db.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null);
            }
            var col = extractCollection(dbs);

            if (col == null)
            {
                return(res);
            }
            foreach (IAbstractObjectStructure obj in col)
            {
                res.Add(obj);
            }
            return(res);
        }
 public DbModelFindReplaceFrame(IDatabaseSource conn)
 {
     InitializeComponent();
     m_conn = conn;
     Async.SafeOpen(m_conn.Connection);
     LoadStructure();
 }
Beispiel #8
0
 public Database_SourceTreeNode(IDatabaseSource conn, ITreeNode parent, string dbname, bool allowPhantom)
     : base(conn, parent, dbname + ((allowPhantom && conn.DatabaseCaps.IsPhantom) ? "_phantom" : ""))
 {
     m_conn   = conn;
     m_dbname = dbname;
     Initialize();
 }
Beispiel #9
0
 public Database_SourceTreeNode(IDatabaseSource conn)
     : base(conn)
 {
     m_conn   = conn;
     m_dbname = conn.DatabaseName;
     Initialize();
 }
Beispiel #10
0
            public override void RunCommand()
            {
                if (Template == null)
                {
                    throw new CommandLineError("DAE-00153 Missing template argument");
                }
                IDatabaseSource db = m_connection.GetConnection();

                Async.SafeOpen(db.Connection);
                IAppObjectSqlGenerator sqlgen = (IAppObjectSqlGenerator)AppObjectSqlGeneratorAddonType.Instance.FindHolder(Template).CreateInstance();
                ISqlDialect            dial;

                if (Dialect != null)
                {
                    dial = (ISqlDialect)DialectAddonType.Instance.FindHolder(Dialect).CreateInstance();
                }
                else
                {
                    dial = new GenericDialect();
                }
                using (TextWriter fw = GetOutputStream())
                {
                    SqlOutputStream so   = new SqlOutputStream(dial, fw, new SqlFormatProperties());
                    ISqlDumper      dmp  = dial.CreateDumper(so, new SqlFormatProperties());
                    var             name = new FullDatabaseRelatedName
                    {
                        ObjectName = new NameWithSchema(Objschema, Objname),
                        ObjectType = Objtype,
                        SubName    = Subname
                    };
                    sqlgen.GenerateSql(db, name, dmp, dial);
                }
                Async.SafeClose(db.Connection);
            }
Beispiel #11
0
        public void LoadStructure(TableStructureMembers members, IDatabaseSource db)
        {
            if (db == null)
            {
                return;             // db not provided, perhaps all is loaded
            }
            if ((members & FilledMembers) == members)
            {
                return;                                       // all is loaded
            }
            var ts = db.InvokeLoadTableStructure(FullName, members) as TableStructure;

            MergeFrom(ts);
            // merge references, not very nice...
            if (ShouldCopy(ts, TableStructureMembers.ReferencedFrom))
            {
                foreach (var fk in ts.GetReferencedFrom())
                {
                    var pkt = ((DatabaseStructure)Database).FindOrCreateTable(fk.Table.FullName);
                    if (pkt.FindConstraint(fk) == null)
                    {
                        pkt._Constraints.Add(new ForeignKey(fk));
                    }
                }
            }
            FilledMembers |= members;
        }
Beispiel #12
0
        void editor_ChangedProperties(object sender, EventArgs e)
        {
            var editor = (NewTableChooserFrame)sender;

            m_name = editor.FullName;
            m_db   = editor.Database;
        }
Beispiel #13
0
            public override void RunCommand()
            {
                IDatabaseSource srcDb = m_source.GetConnection();
                IDatabaseSource dstDb = m_target.GetConnection();

                Async.SafeOpen(srcDb.Connection); Async.SafeOpen(dstDb.Connection);
                var src  = srcDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null);
                var dst  = dstDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null);
                var opts = new DbDiffOptions();

                opts.IgnoreColumnOrder = true;
                //var diff = new DatabaseDiff(src, dst, opts);
                ISqlDialect dial;

                if (Dialect != null)
                {
                    dial = (ISqlDialect)DialectAddonType.Instance.FindHolder(Dialect).CreateInstance();
                }
                else
                {
                    dial = new GenericDialect();
                }
                using (TextWriter fw = GetOutputStream())
                {
                    SqlOutputStream so  = new SqlOutputStream(dial, fw, new SqlFormatProperties());
                    ISqlDumper      dmp = dial.CreateDumper(so, new SqlFormatProperties());
                    dmp.AlterDatabase(src, dst, opts, new DbDefSource(src, DbDefSource.ReadOnly.Flag));
                    //dmp.TargetDb = new DbDefSource(dst, DbDefSource.ReadOnly.Flag);
                    //diff.Actions.GenerateScript(dmp);
                }
                Async.SafeClose(srcDb.Connection); Async.SafeClose(dstDb.Connection);
            }
Beispiel #14
0
        public static MySqlStoredConnection CheckMySqlSourceAndTool(IDatabaseSource source, string tool)
        {
            MySqlSettings cfg = GlobalSettings.Pages.PageByName("mysql_client") as MySqlSettings;

            cfg.GetToolPath(tool);
            return(CheckMySqlSource(source));
        }
Beispiel #15
0
        public static PostgreSqlStoredConnection CheckPostgreSourceAndTool(IDatabaseSource source, string tool)
        {
            PostgreSettings cfg = GlobalSettings.Pages.PageByName("postgre_client") as PostgreSettings;

            cfg.GetToolPath(tool);
            return(CheckPostgreSource(source));
        }
Beispiel #16
0
 public void NotifyChangeTargetDatabase(IDatabaseSource src)
 {
     foreach (var item in Items)
     {
         item.NotifyChangeTargetDatabase(src);
     }
 }
Beispiel #17
0
 public static void InvokeScript(this IDatabaseSource db, Action <ISqlDumper> script, IProgressInfo progress, bool denyTransaction)
 {
     db.Connection.Invoke(
         (Action) delegate()
     {
         db.Connection.SystemConnection.SafeChangeDatabase(db.DatabaseName);
         DbTransaction tran = null;
         if (db.Dialect.DialectCaps.NestedTransactions && !denyTransaction)
         {
             tran = db.Connection.SystemConnection.BeginTransaction();
         }
         try
         {
             db.Connection.RunScript(script, tran, progress);
         }
         catch
         {
             if (tran != null)
             {
                 tran.Rollback();
             }
             throw;
         }
         if (tran != null)
         {
             tran.Commit();
         }
     });
 }
Beispiel #18
0
 public override void NotifyChangeDatabase(IDatabaseSource src)
 {
     if (src.Dialect.DialectCaps.UseDatabaseAsSchema)
     {
         Name = new NameWithSchema(src.DatabaseName, Name.Name);
     }
 }
Beispiel #19
0
        public void DragDrop_CopyDatabase(AppObject draggingObject)
        {
            var conn = this.FindServerConnection();

            if (draggingObject is DatabaseAppObject)
            {
                try
                {
                    IDatabaseSource dsource = ((DatabaseAppObject)draggingObject).FindDatabaseConnection();
                    var             dbprops = new DatabaseProperties();
                    dbprops.Name = dsource.DatabaseName;
                    DatabasePropertiesForm.Run(dbprops, new GenericDatabaseSource(conn, conn.Connection, null), false);
                    //string newname = InputBox.Run(Texts.Get("s_name_of_new_database"), dsource.DatabaseName);
                    //if (newname == null) return;
                    if (ArrayTool.Contains(conn.Databases, dbprops.Name))
                    {
                        StdDialog.ShowError(Texts.Get("s_database_allready_exists"));
                        return;
                    }
                    IDatabaseSource newdb = conn.CreateDatabase(dbprops.Name, dbprops.SpecificData);
                    CopyDbWizard.Run(dsource.CloneSource(), newdb.CloneSource());
                    //CopyDbProcess.StartProcess(dsource.CloneSource(), newdb.CloneSource(), null);
                }
                catch (Exception e)
                {
                    Errors.Report(e);
                }
            }
        }
Beispiel #20
0
 public void NotifyChangeDatabase(IDatabaseSource src)
 {
     if (src.Dialect.DialectCaps.UseDatabaseAsSchema)
     {
         Table = new NameWithSchema(src.DatabaseName, Table.Name);
     }
 }
Beispiel #21
0
 public override void LoadFromXml(XmlElement xml)
 {
     base.LoadFromXml(xml);
     m_backup = new BackupContainer();
     m_backup.LoadFromXml_ForJob(xml.FindElement("Backup"));
     m_dst = (IDatabaseSource)DatabaseSourceAddonType.Instance.LoadAddon(xml.FindElement("Target"));
 }
Beispiel #22
0
 public void NotifyChangeSourceDatabase(IDatabaseSource src)
 {
     if (Source != null)
     {
         Source.NotifyChangeDatabase(src);
     }
 }
        public override IDatabaseWriter GetWriter(string file, IDatabaseSource src)
        {
            var res = new DataArchiveWriter();

            res.FilePlace = FilePlaceAddonType.PlaceFromVirtualFile(file);
            return(res);
        }
Beispiel #24
0
 public void NotifyChangeTargetDatabase(IDatabaseSource src)
 {
     if (Target != null)
     {
         Target.NotifyChangeDatabase(src);
     }
 }
Beispiel #25
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            if (conn != null && objpath != null && conn.SystemConnection != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    string sql = GetSelect(objpath);
                    using (var cmd = conn.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = sql;
                        using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.Read())
                            {
                                return(reader[m_colnumber].SafeToString());
                            }
                        }
                    }
                    return("");
                });
                return(text);
            }
            return("");
        }
Beispiel #26
0
        public MsSqlDatabaseEditor(IDatabaseStructure db, IDatabaseSource conn)
        {
            m_db   = db;
            m_conn = conn;

            Collation = m_db.SpecificData.Get("mssql.collation");
        }
Beispiel #27
0
        public void CreateAllObjects(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            var dbmem = new DatabaseStructureMembers
            {
                TableList             = true,
                TableMembers          = TableStructureMembers.AllNoRefs,
                DomainList            = true,
                DomainDetails         = true,
                SpecificObjectList    = true,
                SpecificObjectDetails = true,
                LoadDependencies      = true,
                IgnoreSystemObjects   = true,
            };
            var dbs   = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            var props = new CreateDatabaseObjectsProps
            {
                CreateDomains         = Domains,
                CreateFixedData       = FixedData,
                CreateSchemata        = Schemata,
                CreateSpecificObjects = SpecificObjects,
                CreateTables          = Tables
            };
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);

            dmp.CreateDatabaseObjects(dbs, props);
        }
Beispiel #28
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();
        }
Beispiel #29
0
        public static void Synchronize(IDatabaseSource src, IDatabaseSource dst, IProgressInfo progress, DataSynDef datasyn, DataSynReportEnv repenv, string outFile, DataSynGuiEnv guienv)
        {
            Synchronizer syn = new Synchronizer(src, dst, progress, datasyn, repenv, outFile, guienv);

            syn.Progress = progress;
            syn.Run();
        }
Beispiel #30
0
        public override void WriteContent(string filename, IDatabaseSource db, Dictionary <string, string> vars, Dictionary <string, object> extnames)
        {
            var fw = DataStore as ITabularDataOuputStream;

            if (fw == null)
            {
                throw new InternalError(String.Format("DAE-00060 Cannot write data to {0}", DataStore));
            }

            using (StreamWriter sw = new StreamWriter(filename))
            {
                using (DbCommand cmd = db.Connection.SystemConnection.CreateCommand())
                {
                    cmd.CommandText = Sql.ReplaceAll(vars);
                    using (IBedReader reader = db.GetAnyDDA().AdaptReader(cmd.ExecuteReader()))
                    {
                        ITableStructure table = reader.Structure;
                        //Path.GetFileNameWithoutExtension(filename));
                        object manager = null;
                        fw.WriteStart(sw, table, ref manager);
                        int index = 0;
                        while (reader.Read())
                        {
                            fw.WriteRecord(sw, table, reader, index, manager);
                            index++;
                        }
                        fw.WriteEnd(sw, table, manager);
                    }
                }
            }
        }