コード例 #1
0
        /// <summary>
        /// Loads the database for this instance.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public override bool LoadSchema(string fileName)
        {
            Database  = new Database(fileName);
            DataNodes = new List <DataNode>();
            var scanner = new DataScanner(Database);
            var tables  = Database.Dmvs.Tables;

            foreach (var table in tables.Where(t => !t.IsMSShipped).OrderBy(t => t.Name))
            {
                var rows      = scanner.ScanTable(table.Name);
                var tableItem = new DataNode();
                tableItem.Name = table.Name;

                var rowData = rows.FirstOrDefault();
                if (rowData != null)
                {
                    foreach (var column in rowData.Columns)
                    {
                        var childItem = new DataNode();
                        childItem.Name     = column.Name;
                        childItem.NodeType = Extensions.GetSQLType(column.Type);
                        childItem.Value    = rowData[column] ?? DBNull.Value;
                        childItem.Parent.Add(tableItem);
                        tableItem.Children.Add(childItem);
                    }
                }

                DataNodes.Add(tableItem);
            }

            return(DataNodes.Count > 0 ? true : false);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: Robin--/OrcaMDF
        public Main(string[] fileNames)
            : this()
        {
            if (fileNames == null || !fileNames.Any())
                return;

            var badFileNames = fileNames.Where(fileName => !File.Exists(fileName));

            if (badFileNames.Any())
            {
                var msg = new StringBuilder("The following files specified on the command line do not exist:");
                msg.AppendLine();
                foreach (var fileName in badFileNames) { msg.AppendFormat("\t{0}{1}", fileName, Environment.NewLine); }
                msg.Append("OrcaMDF.OMS must edit");
                MessageBox.Show(msg.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                Close();
                Environment.Exit(4);
            }

            try
            {
                db = new Database(fileNames);
                refreshTreeview();
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads the database for this instance.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public override bool LoadSchema(string fileName)
        {
            Database  = new Database(fileName);
            DataNodes = new List <DataNode>();
            var scanner = new DataScanner(Database);
            var tables  = Database.Dmvs.Tables.Where(t => !t.IsMSShipped)
                          .OrderBy(t => t.Name).ToList();

            foreach (var table in tables)
            {
                // ignore tables that can't be read successfully
                Row rowData = null;
                try
                {
                    rowData = scanner.ScanTable(table.Name).FirstOrDefault();
                }
                catch
                {
                    LogException(string.Empty, $"Could not get data preview for {table.Name}. A blank record will preview instead.");
                }

                var tableItem = new DataNode
                {
                    Name = table.Name
                };

                // get the table schema
                foreach (var column in Database.Dmvs.Columns.Where(x => x.ObjectID == table.ObjectID))
                {
                    var childItem = new DataNode
                    {
                        Name     = column.Name,
                        NodeType = typeof(string),
                        Value    = DBNull.Value
                    };

                    // try to read data for this table
                    if (rowData != null)
                    {
                        var dataColumn = rowData.Columns.FirstOrDefault(d => d.Name == column.Name);
                        if (dataColumn != null)
                        {
                            childItem.NodeType = GetSQLType(dataColumn.Type) ?? typeof(string);
                            childItem.Value    = rowData[dataColumn] ?? DBNull.Value;
                        }
                    }

                    childItem.Parent.Add(tableItem);
                    tableItem.Children.Add(childItem);
                }

                DataNodes.Add(tableItem);
            }

            return(DataNodes.Count > 0 ? true : false);
        }
コード例 #4
0
        protected void RunDatabaseTest(DatabaseVersion version, Action<Database> test)
        {
            Debug.WriteLine("Test database: " + databaseBaseName);

            // Setup database and store file paths, if we haven't done so already
            ensureDatabaseIsSetup(version);

            // Run actual test
            using (var db = new Database(databaseFiles[version]))
                test(db);
        }
コード例 #5
0
ファイル: BufferManager.cs プロジェクト: Robin--/OrcaMDF
        internal BufferManager(Database db)
        {
            database = db;

            // For each file, instantiate a buffer
            foreach(var file in db.Files.Values)
            {
                buffer.Add(file.FileID, new Dictionary<int, byte[]>());
                fileStreams.Add(file.FileID, new FileStream(file.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read));
            }
        }
コード例 #6
0
ファイル: BaseTableData.cs プロジェクト: Robin--/OrcaMDF
        internal BaseTableData(Database db)
        {
            this.db = db;
            scanner = new DataScanner(db);

            // These are the very core base tables that we'll need to dynamically construct the schema of any other
            // required tables. By aggresively parsing these, we can do lazy loading of the rest.
            parseSysallocunits();
            parseSysrowsets();
            parseSyscolpars();
            parseSysobjects();
            parseSysscalartypes();
            parseSysrscols();
            parseSyssingleobjrefs();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: uldissturms/OrcaMDF
        static void Main()
        {
            //Console.WriteLine("VSS Copying...");
            //VssHelper.CopyFile(@"C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\AdventureWorks_Data.mdf", @"C:\Test.mdf");
            //Console.WriteLine();

            using (var db = new Database(new[] { @"C:\Test.mdf" }))
            {
                foreach (var ic in db.Dmvs.Columns)
                    Console.WriteLine(ic.ObjectID);
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
コード例 #8
0
        internal static IEnumerable<SystemInternalsAllocationUnit> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysallocunits
                    .Select(au => new SystemInternalsAllocationUnit
                        {
                            AllocationUnitID = au.auid,
                            Type = au.type,
                            TypeDesc = db.BaseTables.syspalvalues
                                .Where(ip => ip.@class == "AUTY" && ip.value == au.type)
                                .Select(n => n.name)
                                .Single(),
                            ContainerID = au.ownerid,
                            FilegroupID = au.fgid,
                            FirstPage = new PagePointer(au.pgfirst),
                            RootPage = new PagePointer(au.pgroot),
                            FirstIamPage = new PagePointer(au.pgfirstiam)
                        })
                    .ToList();
            }

            return (IEnumerable<SystemInternalsAllocationUnit>)db.ObjectCache[CACHE_KEY];
        }
コード例 #9
0
ファイル: IndexScanner.cs プロジェクト: Robin--/OrcaMDF
 public IndexScanner(Database database)
     : base(database)
 {
 }
コード例 #10
0
ファイル: ExcavatorComponent.cs プロジェクト: secc/Excavator
        /// <summary>
        /// Loads the database for this instance.
        /// </summary>
        /// <returns></returns>
        public bool LoadSchema( object db )
        {
            // Currently only imports MDF's (using OrcaMDF framework)
            database = (Database)db;
            TableNodes = new List<DatabaseNode>();
            var scanner = new DataScanner( database );
            var tables = database.Dmvs.Tables;

            foreach ( var table in tables.Where( t => !t.IsMSShipped ).OrderBy( t => t.Name ) )
            {
                var rows = scanner.ScanTable( table.Name );
                var tableItem = new DatabaseNode();
                tableItem.Name = table.Name;
                tableItem.NodeType = typeof( object );

                var rowSchema = rows.FirstOrDefault();
                if ( rowSchema != null )
                {
                    foreach ( var column in rowSchema.Columns )
                    {
                        var childItem = new DatabaseNode();
                        childItem.Name = column.Name;
                        childItem.NodeType = Extensions.GetSQLType( column.Type );
                        childItem.Table.Add( tableItem );
                        tableItem.Columns.Add( childItem );
                    }
                }

                TableNodes.Add( tableItem );
            }

            return TableNodes.Count() > 0 ? true : false;
        }
コード例 #11
0
ファイル: ForeignKey.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<ForeignKey> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.Dmvs.ObjectsDollar
                    .Where(o => o.Type == "F")
                    .Select(o => new ForeignKey
                        {
                            Name = o.Name,
                            ObjectID = o.ObjectID,
                            PrincipalID = o.PrincipalID,
                            SchemaID = o.SchemaID,
                            ParentObjectID = o.ParentObjectID,
                            Type = o.Type,
                            TypeDesc = o.TypeDesc,
                            CreateDate = o.CreateDate,
                            ModifyDate = o.ModifyDate,
                            IsMSShipped = o.IsMSShipped,
                            IsPublished = o.IsPublished,
                            IsSchemaPublished = o.IsSchemaPublished,
                            ReferencedObjectID = db.BaseTables.syssingleobjrefs
                                .Where(f => f.depid == o.ObjectID && f.@class == 27 && f.depsubid == 0)
                                .Select(f => f.indepid)
                                .Single(),
                            KeyIndexID = db.BaseTables.syssingleobjrefs
                                .Where(f => f.depid == o.ObjectID && f.@class == 27 && f.depsubid == 0)
                                .Select(f => f.indepsubid)
                                .Single(),
                            IsDisabled = o.IsDisabled,
                            IsNotForReplication = o.IsNotForReplication,
                            IsNotTrusted = o.IsNotTrusted,
                            DeleteReferentialAction = o.DeleteReferentialAction,
                            DeleteReferentialActionDesc = db.BaseTables.syspalvalues
                                .Where(d => d.@class == "FKRA" && d.value == o.DeleteReferentialAction)
                                .Select(d => d.name)
                                .Single(),
                            UpdateReferentialAction = o.UpdateReferentialAction,
                            UpdateReferentialActionDesc = db.BaseTables.syspalvalues
                                .Where(u => u.@class == "FKRA" && u.value == o.UpdateReferentialAction)
                                .Select(u => u.name)
                                .Single(),
                            IsSystemNamed = o.IsSystemNamed
                        })
                    .ToList();
            }

            return (IEnumerable<ForeignKey>)db.ObjectCache[CACHE_KEY];
        }
コード例 #12
0
ファイル: IndexColumn.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<IndexColumn> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysiscols
                   	.Where(ic => (ic.status & 2) != 0)
                   	.Select(ic => new IndexColumn
                   	    {
                   	        ObjectID = ic.idmajor,
                   	        IndexID = ic.idminor,
                   	        IndexColumnID = ic.subid,
                   	        ColumnID = ic.intprop,
                   	        KeyOrdinal = ic.tinyprop1,
                   	        PartitionOrdinal = ic.tinyprop2,
                   	        IsDescendingKey = Convert.ToBoolean(ic.status & 0x4),
                   	        IsIncludedColumn = Convert.ToBoolean(ic.status & 0x10)
                   	    })
                    .ToList();
            }

            return (IEnumerable<IndexColumn>)db.ObjectCache[CACHE_KEY];
        }
コード例 #13
0
ファイル: Index.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Index> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysidxstats
                    .Where(i => (i.status & 1) != 0)
                    .Select(i => new Index
                   		{
                   			ObjectID = i.id,
                   			Name = i.name,
                   			IndexID = i.indid,
                   			Type = i.type,
                   			TypeDesc = db.BaseTables.syspalvalues
                   				.Where(n => n.@class == "IDXT" && n.value == i.type)
                   				.Select(n => n.name)
                   				.Single(),
                   			DataSpaceID = i.dataspace,
                   			FillFactor = i.fillfact,
                   			IsUnique = Convert.ToBoolean(i.status & 0x8),
                   			IsPrimaryKey = Convert.ToBoolean(i.status & 0x20),
                   			IsUniqueConstraint = Convert.ToBoolean(i.status & 0x40),
                   			IsPadded = Convert.ToBoolean(i.status & 0x10),
                   			IsDisabled = Convert.ToBoolean(i.status & 0x80),
                   			IsHypothetical = Convert.ToBoolean(i.status & 0x100),
                   			AllowRowLocks = Convert.ToBoolean(1 - (i.status & 512) / 512),
                   			AllowPageLocks = Convert.ToBoolean(1 - (i.status & 1024) / 1024),
                   			HasFilter = Convert.ToBoolean(i.status & 0x20000)
                   		})
                    .ToList();
            }

            return (IEnumerable<Index>)db.ObjectCache[CACHE_KEY];
        }
コード例 #14
0
ファイル: Table.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Table> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.Dmvs.ObjectsDollar
                    .Where(o => o.Type == "U")
                    .Select(o => new Table
                        {
                            Name = o.Name,
                            ObjectID = o.ObjectID,
                            PrincipalID = o.PrincipalID,
                            SchemaID = o.SchemaID,
                            ParentObjectID = o.ParentObjectID,
                            Type = o.Type,
                            TypeDesc = o.TypeDesc,
                            CreateDate = o.CreateDate,
                            ModifyDate = o.ModifyDate,
                            IsMSShipped = o.IsMSShipped,
                            IsPublished = o.IsPublished,
                            IsSchemaPublished = o.IsSchemaPublished,
                            LobDataSpaceID = db.BaseTables.sysidxstats
                                .Where(lob => lob.id == o.ObjectID && lob.indid <= 1)
                                .Select(lob => (int?)lob.lobds)
                                .SingleOrDefault(),
                            FilestreamDataSpaceID = db.BaseTables.syssingleobjrefs
                                .Where(rfs => rfs.depid == o.ObjectID && rfs.@class == 42 && rfs.depsubid == 0)
                                .Select(rfs => (int?)rfs.indepid)
                                .SingleOrDefault(),
                            MaxColumnIDUsed = o.Property,
                            LockOnBulkLoad = o.LockOnBulkLoad,
                            UsesAnsiNulls = o.UsesAnsiNulls,
                            IsReplicated = o.IsReplicated,
                            HasReplicationFilter = o.HasReplicationFilter,
                            IsMergePublished = o.IsMergePublished,
                            IsSyncTranSubscribed = o.IsSyncTranSubscribed,
                            HasUncheckedAssemblyData = o.HasUncheckedAssemblyData,
                            TextInRowLimit = db.BaseTables.sysidxstats
                                .Where(lob => lob.id == o.ObjectID && lob.indid <= 1)
                                .Select(lob => (int?)lob.intprop)
                                .SingleOrDefault(),
                            LargeValueTypesOutOfRow = o.LargeValueTypesOutOfRow,
                            IsTrackedByCdc = o.IsTrackedByCdc,
                            LockEscalation = o.LockEscalationOption,
                            LockEscalationDesc = db.BaseTables.syspalvalues
                                .Where(ts => ts.@class == "LEOP" && ts.value == o.LockEscalationOption)
                                .Select(ts => ts.name)
                                .Single()
                        })
                    .ToList();
            }

            return (IEnumerable<Table>)db.ObjectCache[CACHE_KEY];
        }
コード例 #15
0
        internal static IEnumerable<SystemInternalsPartitionColumn> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysrscols
                    .Select(c => new {c, ti = new SysrscolTIParser(c.ti)})
                    .Select(x => new SystemInternalsPartitionColumn
                        {
                            PartitionID = x.c.rsid,
                            PartitionColumnID = x.c.rscolid,
                            ModifiedCount = x.c.rcmodified,
                            KeyOrdinal = x.c.ordkey,
                            SystemTypeID = x.ti.TypeID,
                            MaxLength = x.ti.MaxLength,
                            Precision = x.ti.Precision,
                            Scale = x.ti.Scale,
                            MaxInrowLength = x.c.maxinrowlen == 0 ? x.ti.MaxLength : x.c.maxinrowlen,
                            LeafOffset = BitConverter.ToInt16(BitConverter.GetBytes(x.c.offset & 0xFFFF), 0),
                            IsReplicated = Convert.ToBoolean(x.c.status & 1),
                            IsLoggedForReplication = Convert.ToBoolean(x.c.status & 4),
                            IsDropped = Convert.ToBoolean(x.c.status & 2),
                            IsFilestream = Convert.ToBoolean(x.c.status & 32),
                            IsNullable = Convert.ToBoolean(1 - (x.c.status & 128) / 128),
                            IsDescendingKey = Convert.ToBoolean(x.c.status & 8),
                            IsUniqueifier = Convert.ToBoolean(x.c.status & 16),
                            LeafBitPosition = Convert.ToByte(x.c.bitpos & 0xFF),
                            InternalBitPosition = Convert.ToByte(x.c.bitpos / 0x100),
                            IsSparse = Convert.ToBoolean(x.c.status & 0x100),
                            IsAntiMatter = Convert.ToBoolean(x.c.status & 64),
                            InternalOffset = BitConverter.ToInt16(BitConverter.GetBytes((x.c.status & 0xFFFF0000) >> 16), 0),
                            PartitionColumnGuid = x.c.colguid != null ? (Guid?)(new Guid(x.c.colguid)) : null,
                            InternalNullBit = BitConverter.ToInt16(BitConverter.GetBytes((x.c.nullbit & 0xFFFF0000) >> 16), 0),
                            LeafNullBit = BitConverter.ToInt16(BitConverter.GetBytes(x.c.nullbit & 0xFFFF), 0)
                        })
                    .ToList();
            }

            return (IEnumerable<SystemInternalsPartitionColumn>)db.ObjectCache[CACHE_KEY];
        }
コード例 #16
0
ファイル: ObjectDollar.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<ObjectDollar> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysschobjs
                    .Where(o => o.nsclass == 0 && o.pclass == 1)
                    .Select(o => new ObjectDollar
                        {
                            Name = o.name,
                            ObjectID = o.id,
                            PrincipalID = db.BaseTables.syssingleobjrefs
                                .Where(r => r.depid == o.id && r.@class == 97 && r.depsubid == 0)
                                .Select(r => r.indepid)
                                .SingleOrDefault(),
                            SchemaID = o.nsid,
                            ParentObjectID = o.pid,
                            Type = o.type.Trim(),
                            TypeDesc = db.BaseTables.syspalnames
                                .Where(n => n.@class == "OBTY" && n.value.Trim() == o.type.Trim())
                                .Select(n => n.name)
                                .Single(),
                            Property = o.intprop,
                            CreateDate = o.created,
                            ModifyDate = o.modified,
                            IsMSShipped = Convert.ToBoolean(o.status & 1),
                            IsAutoDropped = Convert.ToBoolean(o.status & 2),
                            IsSystemNamed = Convert.ToBoolean(o.status & 4),
                            IsPublished = Convert.ToBoolean(o.status & 16),
                            IsSchemaPublished = Convert.ToBoolean(o.status & 64),
                            LockOnBulkLoad = Convert.ToBoolean(o.status & 256),
                            IsDisabled = Convert.ToBoolean(o.status & 256),
                            IsAutoExecuted = Convert.ToBoolean(o.status & 256),
                            IsActivationEnabled = Convert.ToBoolean(o.status & 256),
                            HasOpaqueMetadata = Convert.ToBoolean(o.status & 512),
                            IsNotForReplication = Convert.ToBoolean(o.status & 512),
                            IsReceiveEnabled = Convert.ToBoolean(o.status & 512),
                            IsNotTrusted = Convert.ToBoolean(o.status & 1024),
                            IsEnqueueEnabled = Convert.ToBoolean(o.status & 1024),
                            WithCheckOption = Convert.ToBoolean(o.status & 1024),
                            IsRetentionEnabled = Convert.ToBoolean(o.status & 2048),
                            HasUncheckedAssemblyData = Convert.ToBoolean(o.status & 2048),
                            UpdateReferentialAction = Convert.ToByte((o.status / 4096) & 3),
                            DeleteReferentialAction = Convert.ToByte((o.status / 16384) & 3),
                            IsReplicated = Convert.ToBoolean(o.status & 0x1000),
                            IsExecutionReplicated = Convert.ToBoolean(o.status & 0x1000),
                            HasReplicationFilter = Convert.ToBoolean(o.status & 0x2000),
                            IsReplSerializableOnly = Convert.ToBoolean(o.status & 0x2000),
                            IsMergePublished = Convert.ToBoolean(o.status & 0x4000),
                            SkipsReplConstraints = Convert.ToBoolean(o.status & 0x4000),
                            IsSyncTranSubscribed = Convert.ToBoolean(o.status & 0x8000),
                            UsesAnsiNulls = Convert.ToBoolean(o.status & 0x40000),
                            NullOnNullInput = Convert.ToBoolean(o.status & 0x200000),
                            UsesDatabaseCollation = Convert.ToBoolean(o.status & 0x100000),
                            IsTrackedByCdc = Convert.ToBoolean(o.status & 0x01000000),
                            LargeValueTypesOutOfRow = Convert.ToBoolean(o.status & 0x02000000),
                            LockEscalationOption = Convert.ToByte((o.status & 0x30000000) / 0x10000000),
                            IsPoisonMessageHandlingEnabled = Convert.ToBoolean(o.status & 0x04000000)
                        })
                    .ToList();
            }

            return (IEnumerable<ObjectDollar>)db.ObjectCache[CACHE_KEY];
        }
コード例 #17
0
ファイル: Column.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Column> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.syscolpars
                    .Where(c => c.number == 0)
                    .Select(c => new Column
                        {
                            ObjectID = c.id,
                            Name = c.name,
                            ColumnID = c.colid,
                            SystemTypeID = c.xtype,
                            UserTypeID = c.utype,
                            MaxLength = c.length,
                            Precision = c.prec,
                            Scale = c.scale,
                            XmlCollectionID = c.xmlns,
                            DefaultObjectID = c.dflt,
                            RuleObjectID = c.chk,
                            IsNullable = Convert.ToBoolean(1 - (c.status & 1)),
                            IsAnsiPadded = Convert.ToBoolean(c.status & 2),
                            IsRowGuidCol = Convert.ToBoolean(c.status & 8),
                            IsIdentity = Convert.ToBoolean(c.status & 4),
                            IsComputed = Convert.ToBoolean(c.status & 16),
                            IsFilestream = Convert.ToBoolean(c.status & 32),
                            IsReplicated = Convert.ToBoolean(c.status & 0x020000),
                            IsNonSqlSubscribed = Convert.ToBoolean(c.status & 0x040000),
                            IsMergePublished = Convert.ToBoolean(c.status & 0x080000),
                            IsDtsReplicated = Convert.ToBoolean(c.status & 0x100000),
                            IsXmlDocument = Convert.ToBoolean(c.status & 2048),
                            IsSparse = Convert.ToBoolean(c.status & 0x1000000),
                            IsColumnSet = Convert.ToBoolean(c.status & 0x2000000)
                        })
                    .ToList();
            }

            return (IEnumerable<Column>)db.ObjectCache[CACHE_KEY];
        }
コード例 #18
0
ファイル: ConnectPage.xaml.cs プロジェクト: secc/Excavator
        /// <summary>
        /// Handles the DoWork event of the bwLoadSchema control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void bwPreview_DoWork( object sender, DoWorkEventArgs e )
        {
            var mdfPicker = new OpenFileDialog();
            mdfPicker.Filter = "SQL Database files|*.mdf";
            mdfPicker.AddExtension = false;

            if ( mdfPicker.ShowDialog() == true )
            {
                var database = new Database( mdfPicker.FileName );
                if ( database != null )
                {
                    var dbType = (string)e.Argument;
                    excavator = frontEndLoader.excavatorTypes.Where( t => t.FullName.Equals( dbType ) ).FirstOrDefault();
                    if ( excavator != null )
                    {
                        bool loadedSuccessfully = excavator.LoadSchema( database );
                        e.Cancel = !loadedSuccessfully;
                    }
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
コード例 #19
0
ファイル: DatabaseMetaData.cs プロジェクト: Robin--/OrcaMDF
 internal DatabaseMetaData(Database db)
 {
     this.db = db;
 }
コード例 #20
0
ファイル: View.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<View> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.Dmvs.ObjectsDollar
                    .Where(o => o.Type == "V")
                    .Select(o => new View
                        {
                            Name = o.Name,
                            ObjectID = o.ObjectID,
                            PrincipalID = o.PrincipalID,
                            SchemaID = o.SchemaID,
                            ParentObjectID = o.ParentObjectID,
                            Type = o.Type,
                            TypeDesc = o.TypeDesc,
                            CreateDate = o.CreateDate,
                            ModifyDate = o.ModifyDate,
                            IsMSShipped = o.IsMSShipped,
                            IsPublished = o.IsPublished,
                            IsSchemaPublished = o.IsSchemaPublished,
                            IsReplicated = o.IsReplicated,
                            HasReplicationFilter = o.HasReplicationFilter,
                            HasOpaqueMetadata = o.HasOpaqueMetadata,
                            HasUncheckedAssemblyData = o.HasUncheckedAssemblyData,
                            WithCheckOption = o.WithCheckOption,
                            IsDateCorrelationView = o.IsAutoDropped,
                            IsTrackedByCdc = o.IsTrackedByCdc
                        })
                    .ToList();
            }

            return (IEnumerable<View>)db.ObjectCache[CACHE_KEY];
        }
コード例 #21
0
ファイル: Scanner.cs プロジェクト: Robin--/OrcaMDF
 protected Scanner(Database database)
 {
     Database = database;
 }
コード例 #22
0
ファイル: Object.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Object> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.Dmvs.ObjectsDollar
                    .Select(o => new Object
                        {
                            Name = o.Name,
                            ObjectID = o.ObjectID,
                            PrincipalID = o.PrincipalID,
                            SchemaID = o.SchemaID,
                            ParentObjectID = o.ParentObjectID,
                            Type = o.Type.Trim(),
                            TypeDesc = o.TypeDesc,
                            CreateDate = o.CreateDate,
                            ModifyDate = o.ModifyDate,
                            IsMSShipped = o.IsMSShipped,
                            IsPublished = o.IsPublished,
                            IsSchemaPublished = o.IsSchemaPublished
                        })
                    .ToList();
            }

            return (IEnumerable<Object>)db.ObjectCache[CACHE_KEY];
        }
コード例 #23
0
ファイル: Type.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Type> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysscalartypes
                    .Select(t => new Type
                        {
                            Name = t.name,
                            SystemTypeID = t.xtype,
                            UserTypeID = t.id,
                            SchemaID = t.schid,
                            MaxLength = t.length,
                            Precision = t.prec,
                            Scale = t.scale,
                            DefaultObjectID = t.dflt,
                            RuleObjectID = t.chk,
                            IsNullable = Convert.ToBoolean(1 - (t.status & 1)),
                            IsUserDefined = t.id > 256,
                            IsAssemblyType = t.xtype == 240,
                            IsTableType = t.xtype == 243,
                            PrincipalID = db.BaseTables.syssingleobjrefs
                                .Where(o => o.depid == t.id && o.@class == 44 && o.depsubid == 0)
                                .Select(o => (int?)o.indepid)
                                .SingleOrDefault()
                        })
                    .ToList();
            }

            return (IEnumerable<Type>)db.ObjectCache[CACHE_KEY];
        }
コード例 #24
0
#pragma warning restore

        #endregion

        #region Methods

        /// <summary>
        /// Loads the database for this instance.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public override bool LoadSchema( string fileName )
        {
            Database = new Database( fileName );
            TableNodes = new List<DatabaseNode>();
            var scanner = new DataScanner( Database );
            var tables = Database.Dmvs.Tables;

            foreach ( var table in tables.Where( t => !t.IsMSShipped ).OrderBy( t => t.Name ) )
            {
                var rows = scanner.ScanTable( table.Name );
                var tableItem = new DatabaseNode();
                tableItem.Name = table.Name;
                tableItem.NodeType = typeof( object );

                var rowData = rows.FirstOrDefault();
                if ( rowData != null )
                {
                    foreach ( var column in rowData.Columns )
                    {
                        var childItem = new DatabaseNode();
                        childItem.Name = column.Name;
                        childItem.NodeType = Extensions.GetSQLType( column.Type );
                        childItem.Table.Add( tableItem );
                        tableItem.Columns.Add( childItem );
                        tableItem.Value = rowData[column] ?? DBNull.Value;
                    }
                }

                TableNodes.Add( tableItem );
            }

            return TableNodes.Count() > 0 ? true : false;
        }
コード例 #25
0
ファイル: SqlModule.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<SqlModule> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                var types = new [] { "TR", "P", "V", "FN", "IF", "TF", "RF", "IS", "R", "D" };

                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysschobjs
                    .Where(o => o.pclass != 100 && types.Contains(o.type.Trim()))
                    .Select(o => new SqlModule
                        {
                            ObjectID = o.id,
                            Definition = db.BaseTables.sysobjvalues
                                .Where(v => v.objid == o.id)
                                .Select(v => Encoding.ASCII.GetString(v.imageval))
                                .FirstOrDefault(),
                            UsesAnsiNulls = Convert.ToBoolean(o.status & 0x40000),
                            UsesQuotedIdentifier = Convert.ToBoolean(o.status & 0x80000),
                            IsSchemaBound = Convert.ToBoolean(o.status & 0x20000),
                            UsesDatabaseCollation = Convert.ToBoolean(o.status & 0x100000),
                            IsRecompiled = Convert.ToBoolean(o.status & 0x400000),
                            NullOnNullInput = Convert.ToBoolean(o.status & 0x200000),
                            ExecuteAsPrincipalID =
                                db.BaseTables.syssingleobjrefs.Where(x => x.depid == o.id && x.@class == 22 && x.depsubid == 0).
                                Select(x => x.indepid).FirstOrDefault()
                        })
                    .ToList();
            }

            return (IEnumerable<SqlModule>)db.ObjectCache[CACHE_KEY];
        }
コード例 #26
0
ファイル: Partition.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Partition> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysrowsets
                    .Select(rs => new Partition
                        {
                            PartitionID = rs.rowsetid,
                            ObjectID = rs.idmajor,
                            IndexID = rs.idminor,
                            PartitionNumber = rs.numpart,
                            HobtID = rs.rowsetid,
                            Rows = 0, // TODO
                            FilestreamFilegroupID = rs.fgidfs,
                            DataCompression = rs.cmprlevel,
                            DataCompressionDesc = db.BaseTables.syspalvalues
                                .Where(cl => cl.@class == "CMPL" && cl.value == rs.cmprlevel)
                                .Select(cl => cl.name)
                                .SingleOrDefault(),
                        })
                    .ToList();
            }

            return (IEnumerable<Partition>)db.ObjectCache[CACHE_KEY];
        }
コード例 #27
0
ファイル: DmvGenerator.cs プロジェクト: Robin--/OrcaMDF
 internal DmvGenerator(Database db)
 {
     this.db = db;
 }
コード例 #28
0
        internal static IEnumerable<SystemInternalsPartition> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.BaseTables.sysrowsets
                    .Select(rs => new SystemInternalsPartition
                        {
                            PartitionID = rs.rowsetid,
                            ObjectID = rs.idmajor,
                            IndexID = rs.idminor,
                            PartitionNumber = rs.numpart,
                            FilestreamFilegroupID = rs.fgidfs,
                            MaxNullBitUsed = rs.maxnullbit,
                            MaxLeafLength = rs.maxleaf,
                            MinLeafLength = rs.minleaf,
                            MaxInternalLength = rs.maxint,
                            MinInternalLength = rs.minint,
                            FilestreamGuid = rs.rsguid != null ? (Guid?)(new Guid(rs.rsguid)) : null,
                            IsOrphaned = Convert.ToBoolean(1 - rs.ownertype),
                            DroppedLobColumnState = Convert.ToByte(rs.status & 3),
                            IsUnique = Convert.ToBoolean(rs.status & 4),
                            IsReplicated = Convert.ToBoolean(rs.status & 8),
                            IsLoggedForReplication = Convert.ToBoolean(rs.status & 16),
                            AllowsNullableKeys = Convert.ToBoolean(rs.status & 64),
                            AllowRowLocks = Convert.ToBoolean(1 - (rs.status & 256) / 256),
                            AllowPageLocks = Convert.ToBoolean(1 - (rs.status & 256) / 256),
                            IsDataRowFormat = Convert.ToBoolean(rs.status & 512),
                            IsNotVersioned = Convert.ToBoolean(rs.status & 2048)
                        })
                    .ToList();
            }

            return (IEnumerable<SystemInternalsPartition>)db.ObjectCache[CACHE_KEY];
        }
コード例 #29
0
ファイル: Main.cs プロジェクト: Robin--/OrcaMDF
        private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var result = openDatabaseDialog.ShowDialog();

            if(result == DialogResult.OK)
            {
                try
                {
                    var files = openDatabaseDialog.FileNames;
                    db = new Database(files);

                    refreshTreeview();
                }
                catch (Exception ex)
                {
                    logException(ex);
                }
            }
        }
コード例 #30
0
ファイル: Procedure.cs プロジェクト: Robin--/OrcaMDF
        internal static IEnumerable<Procedure> GetDmvData(Database db)
        {
            if (!db.ObjectCache.ContainsKey(CACHE_KEY))
            {
                db.ObjectCache[CACHE_KEY] = db.Dmvs.ObjectsDollar
                    .Where(o => (
                        o.Type == "P" ||
                        o.Type == "X" ||
                        o.Type == "PC" ||
                        o.Type == "RF"
                    )).Select(o => new Procedure
                        {
                            Name = o.Name,
                            ObjectID = o.ObjectID,
                            PrincipalID = o.PrincipalID,
                            SchemaID = o.SchemaID,
                            ParentObjectID = o.ParentObjectID,
                            Type = o.Type,
                            TypeDesc = o.TypeDesc,
                            CreateDate = o.CreateDate,
                            ModifyDate = o.ModifyDate,
                            IsMSShipped = o.IsMSShipped,
                            IsPublished = o.IsPublished,
                            IsSchemaPublished = o.IsSchemaPublished,
                            IsAutoExecuted = o.IsAutoExecuted,
                            IsExecutionReplicated = o.IsExecutionReplicated,
                            IsReplSerializableOnly = o.IsReplSerializableOnly,
                            SkipsReplConstraints = o.SkipsReplConstraints
                        })
                    .ToList();
            }

            return (IEnumerable<Procedure>)db.ObjectCache[CACHE_KEY];
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: windancer79/OrcaMDF
        static void Main(string[] args)
        {
            var db      = new OrcaMDF.Core.Engine.Database(@"C:\work\DDB.mdf");
            var scanner = new DDB_DataScanner(db);
            var rows    = scanner.ScanTable("stu");

            List <String> colNames = new List <string>();

            colNames.Add("aid");
            colNames.Add("namec");
            int            rowSize = 20000000;
            List <IVector> cols    = new List <IVector>();

            cols.Add(new BasicIntVector(rowSize));
            cols.Add(new BasicStringVector(rowSize));
            bt = new BasicTable(colNames, cols);
            Console.WriteLine("prepared basicTable ");
            //int rowIndex = 0;
            //foreach (var scannedRow in tb)
            //{
            //    for (int colIndex = 0;colIndex < cols.Count;colIndex++)
            //    {
            //        IVector v = cols[colIndex];
            //        switch (v.getDataType())
            //        {
            //            case DATA_TYPE.DT_INT:
            //                v.set(rowIndex, new BasicInt((int)scannedRow[scannedRow.Columns[colIndex]]));
            //                break;
            //            case DATA_TYPE.DT_STRING:
            //                v.set(rowIndex, new BasicString((string)scannedRow[scannedRow.Columns[colIndex]]));
            //                break;
            //        }
            //    }
            //    rowIndex++;
            //}
            //BasicTable bt = new BasicTable(colNames, cols);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            //人工确定size
            Task t1 = ReadTask.getTask();

            t1.Start();
            Task t2 = ParserTask.getTask();

            t2.Start();
            Task.WaitAll(t1, t2);
            sw.Stop();
            Console.WriteLine("read and parse cost: " + sw.ElapsedMilliseconds);
            sw.Reset();
            sw.Restart();
            Task t3 = UploadTask.getTask();

            t3.Start();
            Task.WaitAll(t3);
            sw.Stop();
            Console.WriteLine("upload cost: " + sw.ElapsedMilliseconds);
            Console.ReadLine();
            //Console.WriteLine("starting upload data!");
            //DateTime dt_end1 = DateTime.Now;

            //DBConnection conn = new DBConnection();
            //conn.connect("192.168.1.135", 8981, "admin", "123456");

            //var variable = new Dictionary<string, IEntity>() ;
            //variable.Add("table1", bt);
            //conn.upload(variable);
            //conn.run("share table1 as sql_table");
            //DateTime dt_end2 = DateTime.Now;

            //TimeSpan readtime = dt_end1 - dt_st1;
            //TimeSpan uploadtime = dt_end2 - dt_end1;

            //Console.WriteLine("read cost : ");
            //Console.WriteLine(readtime.TotalSeconds);
            //Console.WriteLine("upload cost : ");
            //Console.WriteLine(uploadtime.TotalSeconds);
            //Console.ReadLine();
        }