public void Commit( CommitStage c ) { if ( Saved ) return; if ( c == CommitStage.Prepare ) { // Save the pages to the underlying stream. foreach ( G.KeyValuePair<long,IndexPage> pair in PageMap ) { IndexPage p = pair.Value; if ( !p.Saved ) { p.WriteHeader(); F.Position = (long)p.PageId * IndexPage.PageSize; // For last page, only write the amount actually used (so file size is minimised) F.Write( p.Data, 0, p.PageId == PageAlloc-1 ? p.Size() : IndexPage.PageSize ); p.Saved = true; } } } else if ( c == CommitStage.Rollback ) { PageMap.Clear(); Initialise(); } else F.Commit( c ); if ( c >= CommitStage.Flush ) Saved = true; }
void Save(long id, Value [] row, bool checkNew) { DF.Position = (id - 1) * RowSize; if (row == null) // Delete record { for (int i = 0; i < RowSize; i += 1) { RB[i] = 0; } } else { DataType [] types = Cols.Types; byte [] sizes = Cols.Sizes; RB[0] = 1; int ix = 1; for (int i = 1; i < types.Length; i += 1) { DataType t = types[i]; ulong x = (ulong)row[i].L; if (t <= DataType.String && x == 0) { object o = row[i]._O; x = (t == DataType.Binary ? (ulong)Db.EncodeBinary((byte[])o) : (ulong)Db.EncodeString((string)o)); row[i].L = (long)x; } else if (t == DataType.Float) { x = Conv.PackFloat(x); } int size = sizes[i]; Util.Set(RB, ix, x, size); ix += size; } } if (!DF.Write(RB, 0, RowSize, checkNew)) { throw new System.Exception("Duplicate id, id=" + id + " Table=" + Schema + "." + Name); } Dirty = true; }
void Save(long id, Value [] row, bool checkNew) { DataFile.Position = (id - 1) * RowSize; if (row == null) // Delete record { for (int i = 0; i < RowSize; i += 1) { RowBuffer[i] = 0; } } else { RowBuffer[0] = 1; int ix = 1; for (int i = 1; i < CI.Count; i += 1) { DataType t = CI.Type[i]; long x = row[i].L; if (t <= DataType.String && x == 0) { x = Database.Encode(row[i]._O, t); row[i].L = x; } else if (t == DataType.Float) { x = (long)Conv.PackFloat(x); } int size = Size[i]; Util.Set(RowBuffer, ix, x, size); ix += size; } } if (!DataFile.Write(RowBuffer, 0, RowSize, checkNew)) { throw new System.Exception("Duplicate id"); } Dirty = true; }