コード例 #1
0
  public TableExpression GetTableOrView( string schemaName, string name, Exec e )
  {
    Schema schema = GetSchema( schemaName, true, e );
    TableExpression result = schema.GetCachedTable( name ); 
    if ( result != null ) return result;

    bool isView; string definition;
    long tid = ReadTableId( schema, name, out isView, out definition );
    if ( tid < 0 ) e.Error( schemaName + "." + name + " not found" );

    if ( isView )
    {
      TableExpression te = e.LoadView( definition, schemaName + "." + name );
      te.TableId = tid;
      schema.TableDict[ name ] = te;
      return te;
    }
    else
    {
      // Fetch the Column Information from the SysColumn table.
      var names = new G.List<string>(); 
      var types = new G.List<DataType>();
      names.Add( "Id" ); types.Add( DataType.Bigint ); // Add the pre-defined "id" column.

      // Use SysColumnIndex to avoid scanning the entire SysColumn table.
      var start = new LongStart( tid );
      var r = new RowCursor( SysColumn );

      foreach( IndexFileRecord ixr in SysColumnIndex.From( start.Compare, false ) )
      {
        if ( ixr.Col[0].L == tid )
        {
          r.Get( ixr.Col[1].L );
          names.Add( (string) r.V[2]._O );
          types.Add( (DataType)r.V[3].L );
        }
        else break;
      }

      Table t = new Table( this, schema, name, ColInfo.New(names,types), tid );
      t.OpenIndexes();
      return t;
    }
  }
コード例 #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();
  }