コード例 #1
0
        public static IndexInfo[] Single(long indexId, int cix)
        {
            var a = new IndexInfo[1];

            a[0].IndexId = indexId;
            a[0].IxNum   = 0;
            a[0].ColIx   = cix;
            return(a);
        }
コード例 #2
0
  public IndexInfo [] ReadIndexes( long tableId )
  {
    var ix = new G.List<IndexInfo>();
    var r = new RowCursor( SysIndexCol );
    long CurIx = 0;
    int IxNum = 0;

    // Use SysIndexColIndex to avoid scanning the entire SysIndexCol table.
    var start = new LongStart( tableId );
    foreach( IndexFileRecord ixr in SysIndexColIndex.From( start.Compare, false ) )
    {
      if ( ixr.Col[0].L == tableId )
      {
        r.Get( ixr.Col[1].L );
        var ii = new IndexInfo();
        ii.IndexId = r.V[2].L;
        if ( ii.IndexId != CurIx ) { IxNum = 0; CurIx = ii.IndexId; }
        ii.IxNum = IxNum++;
        ii.ColIx = (int)r.V[3].L; 
        ix.Add( ii );
      } else break;
    }
    return ix.ToArray();
  }
コード例 #3
0
  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