Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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));
            }
        }
        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);
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        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();
        }
Exemple #6
0
 public IndexScanner(Database database)
     : base(database)
 {
 }
Exemple #7
0
        /// <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;
        }
Exemple #8
0
 internal DmvGenerator(Database db)
 {
     this.db = db;
 }
Exemple #9
0
        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 && [email protected] == 27 && f.depsubid == 0)
                                .Select(f => f.indepid)
                                .Single(),
                            KeyIndexID = db.BaseTables.syssingleobjrefs
                                .Where(f => f.depid == o.ObjectID && [email protected] == 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 => [email protected] == "FKRA" && d.value == o.DeleteReferentialAction)
                                .Select(d => d.name)
                                .Single(),
                            UpdateReferentialAction = o.UpdateReferentialAction,
                            UpdateReferentialActionDesc = db.BaseTables.syspalvalues
                                .Where(u => [email protected] == "FKRA" && u.value == o.UpdateReferentialAction)
                                .Select(u => u.name)
                                .Single(),
                            IsSystemNamed = o.IsSystemNamed
                        })
                    .ToList();
            }

            return (IEnumerable<ForeignKey>)db.ObjectCache[CACHE_KEY];
        }
Exemple #10
0
 protected Scanner(Database database)
 {
     Database = database;
 }
Exemple #11
0
        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];
        }
#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;
        }
Exemple #13
0
        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];
        }
        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 => [email protected] == "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];
        }
Exemple #15
0
        /// <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;
            }
        }
Exemple #16
0
 internal DatabaseMetaData(Database db)
 {
     this.db = db;
 }
Exemple #17
0
        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);
                }
            }
        }
Exemple #18
0
        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];
        }
Exemple #19
0
        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];
        }
        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];
        }
Exemple #21
0
        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 && [email protected] == 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 => [email protected] == "LEOP" && ts.value == o.LockEscalationOption)
                                .Select(ts => ts.name)
                                .Single()
                        })
                    .ToList();
            }

            return (IEnumerable<Table>)db.ObjectCache[CACHE_KEY];
        }
Exemple #22
0
        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 && [email protected] == 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 => [email protected] == "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];
        }
Exemple #23
0
        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 => [email protected] == "CMPL" && cl.value == rs.cmprlevel)
                                .Select(cl => cl.name)
                                .SingleOrDefault(),
                        })
                    .ToList();
            }

            return (IEnumerable<Partition>)db.ObjectCache[CACHE_KEY];
        }
Exemple #24
0
        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 => [email protected] == "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];
        }
        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];
        }
Exemple #26
0
        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 && [email protected] == 22 && x.depsubid == 0).
                                Select(x => x.indepid).FirstOrDefault()
                        })
                    .ToList();
            }

            return (IEnumerable<SqlModule>)db.ObjectCache[CACHE_KEY];
        }
Exemple #27
0
        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];
        }
Exemple #28
0
        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 && [email protected] == 44 && o.depsubid == 0)
                                .Select(o => (int?)o.indepid)
                                .SingleOrDefault()
                        })
                    .ToList();
            }

            return (IEnumerable<Type>)db.ObjectCache[CACHE_KEY];
        }