コード例 #1
0
  public void CreateTable( string schemaName, string tableName, ColInfo cols, string definition, bool isView, bool alter, Exec e )
  {
    Schema schema = GetSchema( schemaName, true, e );

    bool isView1; string definition1;
    long tableId = tableId = ReadTableId( schema, tableName, out isView1, out definition1 );

    if ( alter ) 
    {
      if ( tableId == 0 || !isView1 ) e.Error( "View does not exist" );
    }
    else if ( Normal && schema.GetCachedTable( tableName ) != null || tableId >= 0 ) 
      e.Error( "Table/View " + schemaName + "." + tableName + " already exists" );

    var r = new RowCursor( SysTable );
    r.V[1].L = schema.Id;
    r.V[2].O = tableName;
    r.V[3].L = isView ? 1 : 0;
    r.V[4].O = isView ? definition.Trim() : "";

    if ( alter ) r.Update( tableId ); else tableId = r.Insert();

    if ( !isView) SaveColumns( tableId, cols );
    if ( isView ) ResetCache();
  }
コード例 #2
0
  // Schema methods Create/Drop Schema, Table, View, Function, Procedure, Index etc.

  public void CreateSchema( string schemaName, Exec e )
  {
    if ( Normal && GetSchemaId( schemaName, false, e ) >= 0 ) 
      e.Error( "Schema already exists : " + schemaName );
    var r = new RowCursor( SysSchema );
    r.V[1].O = schemaName;
    r.Insert();
  }
コード例 #3
0
 void SaveColumns( long tableId, ColInfo cols )
 {
   var r = new RowCursor( SysColumn );
   r.V[1].L = tableId;
   for ( int i = 0; i < cols.Count; i += 1 )
   {
     r.V[2].O = cols.Names[i];
     r.V[3].L = (long)cols.Types[i];
     r.Insert();
   }
 }
コード例 #4
0
  // Indexes.

  public void CreateIndex( string schemaName, string tableName, string indexName, string [] names, Exec e )
  {
    Table t = (Table)GetTable( schemaName, tableName, e );
    long tid = t.TableId;

    long indexId = GetIndexId( tid, indexName );
    if ( indexId != 0 ) e.Error( "Index already exists" );

    int [] colIx = new int[ names.Length ];
    for ( int i=0; i < names.Length; i +=1 )
    {
      colIx[ i ] = t.ColumnIx( names[i], e );
    }    

    // Create the index.
    {
      var r = new RowCursor( SysIndex );
      r.V[1].L = tid;
      r.V[2].O = indexName;
      indexId = r.Insert();
    }
    // Create the index columns.
    {
      var r = new RowCursor( SysIndexCol );
      r.V[1].L = tid;
      r.V[2].L = indexId;
      for ( int i = 0; i < names.Length; i += 1 )
      {
        r.V[3].L = colIx[ i ];
        r.Insert();
      }
    }

    if ( Normal ) 
    {
      t.OpenIndexes();
      t.InitIndex( indexId );
    }
  }