コード例 #1
0
ファイル: IndexPage.cs プロジェクト: georgebarwood/Database
        public IndexPage(IndexFileInfo inf, byte [] data, DatabaseImp database)
        {
            if (inf.KeyCount > 100)
            {
                throw new System.Exception("Max number of index columns exceeded");
            }
            Inf      = inf;
            Database = database;
            bool leaf = IsLeafPage();

            ColStore = leaf ? inf.KeyCount : inf.Types.Length; // Currently these are the same.
            NodeSize = NodeOverhead + inf.KeySize() + (leaf ? 0 : PageIdSize);
            NodeBase = FixedHeader + (leaf ? 0 : PageIdSize) - NodeSize;

            MaxNode = (PageSize - (NodeBase + NodeSize)) / NodeSize;
            if (MaxNode > 2047)
            {
                MaxNode = 2047;           // Node ids are 11 bits.
            }
            if (data == null)
            {
                Data = new byte[PageSize];
            }
            else
            {
                Data = data;
                ReadHeader();
            }
            // Console.WriteLine( "New IndexPage Count=" + Count + " ColStore=" + ColStore + " NodeSize=" + NodeSize + " MaxNode=" + MaxNode );
        }
コード例 #2
0
        public void OpenIndexes(IndexInfo[] info)
        {
            IxInfo = info;

            long curIndex = -1;
            var  dt       = new G.List <DataType>();
            var  cm       = new G.List <int>();

            for (int i = 0; i <= info.Length; i += 1)
            {
                if (i > 0 && (i == info.Length || info[i].IndexId != curIndex))
                {
                    IndexFileInfo ci = new IndexFileInfo();
                    dt.Add(DataType.Bigint); // For id value
                    ci.KeyCount = dt.Count;
                    ci.Types    = dt.ToArray();
                    ci.BaseIx   = cm.ToArray();
                    ci.IndexId  = curIndex;
                    OpenIndex(curIndex, ci);
                    dt = new G.List <DataType>();
                    cm = new G.List <int>();
                }
                if (i != info.Length)
                {
                    curIndex = info[i].IndexId;
                    int colIx = info[i].ColIx;
                    dt.Add(CI.Type[colIx]);
                    cm.Add(colIx);
                }
            }
        }
コード例 #3
0
 public IndexFile( FullyBufferedStream f, IndexFileInfo inf, DatabaseImp d, long indexId )
 {
   F = f; Inf = inf; Database = d; IndexId = indexId;
   Initialise();
   //System.Console.WriteLine("New IndexFile " + " Root=" + Root + " PageAlloc=" + PageAlloc );
   //Dump();
 }
コード例 #4
0
 public string ToString( IndexFileInfo Inf ) // For debugging / testing only.
 {
   string s = "";
   for ( int i = 0 ; i < Inf.Types.Length; i+= 1 )
   {
     s += Util.ToString( Col[ i ], Inf.Types[ i ] ) + "|";
   }
   return s;
 }
コード例 #5
0
        public void OpenIndex(long indexId, IndexFileInfo ci)
        {
            IndexFile ixf;

            IxDict.TryGetValue(indexId, out ixf);
            if (ixf == null)
            {
                var stream = Database.OpenFile(FileType.Index, indexId);
                IxDict[indexId] = new IndexFile(stream, ci, Database, indexId);
            }
        }
コード例 #6
0
ファイル: IndexPage.cs プロジェクト: georgebarwood/Database
 public PageParent(IndexFileInfo inf, byte [] data, DatabaseImp d) : base(inf, data, d)
 {
 }
コード例 #7
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