// For implementation of Alter Table. public void AlterData(ColInfo newcols, int[] map) { // For each record, read the old data, copy the columns, write the new data. // Each column in the new table will either be new, in which case it gets a default value, // or is copied from an old column. The types do not have to match exactly, but need to have the same base type. // Map holds the old colId for eaach new column ( or -1 if it is a new column ). // Doesn't currently check for overflow. long [] oldRow = new long[Cols.Count]; long [] newRow = new long[newcols.Count]; // Initialise newRow to default values. for (int i = 0; i < newRow.Length; i += 1) { newRow[i] = DTI.Default(newcols.Types[i]).L; } int newRowSize = CalcRowSize(newcols); byte [] blank = new byte[newRowSize]; RB = new byte[newRowSize]; // So that old data is not over-written before it has been converted, if new row size is bigger, use descending order. bool desc = newRowSize > RowSize; long id = desc ? RowCount - 1 : 0; // Note : zero based, whereas actual id values are 1-based. long n = RowCount; while (n > 0) { DF.Position = id * RowSize; bool ok = AlterRead(Cols.Types, oldRow); for (int i = 0; i < newRow.Length; i += 1) { int m = map[i]; if (m >= 0) { newRow[i] = oldRow[m]; } } DF.Position = id * newRowSize; if (ok) { AlterWrite(newcols.Types, newRow, newRowSize); } else { DF.Write(blank, 0, blank.Length); } n -= 1; id = desc ? id - 1 : id + 1; } if (!desc) { DF.SetLength(RowCount * newRowSize); } Dirty = true; RowSize = newRowSize; Cols = newcols; }
public Inserter(Table t, int[] colIx, int idCol, TableExpression te) { T = t; ColIx = colIx; IdCol = idCol; TE = te; DataType [] types = t.CI.Type; Row = new Value[types.Length]; // Initialise row to default values. for (int i = 0; i < types.Length; i += 1) { Row[i] = DTI.Default(types[i]); } }
public Inserter(Table t, int[] colIx, int idCol, TableExpression te) { T = t; ColIx = colIx; IdCol = idCol; TE = te; DataType [] types = t.Cols.Types; Row = new Value[types.Length]; // The line below is not required as Writer.SaveRecord handles any nulls, but this may be safer. for (int i = 0; i < types.Length; i += 1) { Row[i] = DTI.Default(types[i]); } }