Example #1
0
        private void ShowDataTypeCode(string dataTypeName, SysSchema schema)
        {
            // Get procedure ID
            //var objId = _db.Dmvs.Types
            //    .Where(p => p.Name == dataTypeName && schema.schema_id == p.SchemaID && !p.IsTableType && p.IsUserDefined)
            //    .Select(p => p.ObjectID)
            //    .Single();

            //// Get definition from sql_modules
            //var definition = _db.Dmvs.SqlModules
            //    .Where(m => m.ObjectID == objId)
            //    .Select(m => m.Definition)
            //    .Single();

            //// Set code
            //txtCode.Text = definition;
            //txtCode.Refresh();
            //grid.Visible = false;
            //txtCode.Visible = true;
        }
Example #2
0
        private void ShowViewCode(string viewName, SysSchema schema)
        {
            // Get view ID
            var objId = Database.Dmvs.Views
                        .Where(p => p.Name == viewName && schema.schema_id == p.SchemaID)
                        .Select(p => p.ObjectID)
                        .Single();

            // Get definition from sql_modules
            var definition = Database.Dmvs.SqlModules
                             .Where(m => m.ObjectID == objId)
                             .Select(m => m.Definition)
                             .Single();

            // Set code
            txtCode.Text = definition;
            txtCode.Refresh();
            grid.Visible        = false;
            txtCode.Visible     = true;
            gridStatusRows.Text = string.Empty;
        }
Example #3
0
        private void ShowTableFunctionCode(string functionName, SysSchema schema)
        {
            // Get procedure ID
            var objId = Database.Dmvs.Functions
                        .Where(p => p.Name == functionName && schema.schema_id == p.SchemaID && new[] { "TF", "IF" }.Contains(p.Type))
                        .Select(p => p.ObjectID)
                        .Single();

            // Get definition from sql_modules
            var definition = Database.Dmvs.SqlModules
                             .Where(m => m.ObjectID == objId)
                             .Select(m => m.Definition)
                             .Single();

            // Set code
            txtCode.Text = definition;
            txtCode.Refresh();
            grid.Visible        = false;
            txtCode.Visible     = true;
            gridStatusRows.Text = string.Empty;
        }
  public DatabaseImp( string dirName )
  {
    Name = dirName;
    Log = new Log( Name );
    Sys = GetSchema( "sys", true, null );

    {
      SysString = OpenFile(  FileType.System, 0 );
      SysStringReader = new BinaryReader( SysString );
      SysStringWriter = new BinaryWriter( SysString );

      IndexFileInfo ii = new IndexFileInfo();
      ii.KeyCount = 1;
      ii.Types = new DataType[] { DataType.String };
      var f = OpenFile( FileType.System, 1 );
      SysStringIndex = new IndexFile( f, ii, this, -1 );
    }

    {
      SysBinary = OpenFile( FileType.System, 2 );
      SysBinaryReader = new BinaryReader( SysBinary );
      SysBinaryWriter = new BinaryWriter( SysBinary );

      IndexFileInfo ii = new IndexFileInfo();
      ii.KeyCount = 1;
      ii.Types = new DataType[] { DataType.Binary };
      var f = OpenFile( FileType.System, 3 );
      SysBinaryIndex = new IndexFile( f, ii, this, -2 );
    }

    var cb = new ColBuilder();

    cb.Add( "Name", DataType.String );
    SysSchema = NewSysTable( 1, "Schema", cb.Get() );

    cb.Add( "Schema", DataType.Int );
    cb.Add( "Name",   DataType.String );
    cb.Add( "IsView", DataType.Tinyint );
    cb.Add( "Definition", DataType.String );
    SysTable = NewSysTable( 2, "Table", cb.Get() );

    cb.Add( "Table",    DataType.Int );
    cb.Add( "Name",     DataType.String );
    cb.Add( "Type",     DataType.Int );
    SysColumn = NewSysTable( 3, "Column", cb.Get() );

    cb.Add( "Table",    DataType.Int );
    cb.Add( "Name",     DataType.String );
    cb.Add( "Modified", DataType.Tinyint );
    SysIndex = NewSysTable( 4, "Index", cb.Get() );

    cb.Add( "Table",    DataType.Int );
    cb.Add( "Index",    DataType.Int );
    cb.Add( "ColId",    DataType.Int );
    SysIndexCol = NewSysTable( 5, "IndexCol", cb.Get() );

    SysColumn.OpenIndexes( IndexInfo.Single( 1, 1 ) );
    SysColumnIndex = SysColumn.FindIndex( 1 );

    SysIndexCol.OpenIndexes( IndexInfo.Single( 2, 1) );
    SysIndexColIndex = SysIndexCol.FindIndex( 1 );

    SysSchema.OpenIndexes( IndexInfo.Single( 3, 1 ) );
    SysSchemaByName = SysSchema.FindIndex( 1 );

    SysTable.OpenIndexes( IndexInfo.Single( 4, 2 ) );
    SysTableByName = SysTable.FindIndex( 2 );

    if ( SysSchema.RowCount == 0 )
    {
      IsNew = true;
      Sql( "CREATE SCHEMA sys" ); // Note these are created in TableId order.
      Sql( "CREATE TABLE sys.Schema( Name string )" );
      Sql( "CREATE TABLE sys.Table( Schema int, Name string, IsView tinyint, Definition string )" );
      Sql( "CREATE TABLE sys.Column( Table int, Name string, Type int )" );
      Sql( "CREATE TABLE sys.Index( Table int, Name string, Modified tinyint )" );
      Sql( "CREATE TABLE sys.IndexCol( Table int, Index int, ColId int )" );
      Sql( "CREATE INDEX ColumnByTable on sys.Column(Table)" );
      Sql( "CREATE INDEX IndexColByTable on sys.IndexCol(Table)" );
      Sql( "CREATE INDEX SchemaByName on sys.Schema(Name)" );
      Sql( "CREATE INDEX TableByName on sys.Table(Name)" );
      Normal = true;

      Sql( "CREATE TABLE sys.Function( Schema int, Name string, Definition string )" );
      Sql( "CREATE INDEX FunctionByName on sys.Function(Name)" );

      Sql( "CREATE TABLE sys.Procedure( Schema int, Name string, Definition string )" );
      Sql( "CREATE INDEX ProcedureByName on sys.Procedure(Name)" );
    }
    RollbackOrCommit();
    Normal = true;
  } // end DatabaseImp