diff --git a/compiler/gengo/gen_cmd.go b/compiler/gengo/gen_cmd.go index 85dbaa9..82e5f27 100644 --- a/compiler/gengo/gen_cmd.go +++ b/compiler/gengo/gen_cmd.go @@ -132,7 +132,8 @@ func (g *Generator) emitReplaceCmd(s *ast.ReplaceCmd, locals localMap) { g.writeln("}") } } - g.writeln("area.Flush()") + // No Flush here — Harbour defers write until DBCOMMIT/CLOSE/GoTo. + // PutValue sets dirty flag; flushRecord writes on next GoTo or Close. g.indent-- g.writeln("}") diff --git a/hbrdd/dbf/indexer.go b/hbrdd/dbf/indexer.go index 8050505..b8c3f25 100644 --- a/hbrdd/dbf/indexer.go +++ b/hbrdd/dbf/indexer.go @@ -63,6 +63,13 @@ func (a *DBFArea) ensureIndexState() { func (a *DBFArea) OrderCreate(params hbrdd.OrderCreateParams) error { a.ensureIndexState() + // Flush pending record + update header/EOF before index build + if a.dirty { + a.flushRecord() + } + a.dataFile.WriteAt([]byte{EOFMarker}, a.header.EOFOffset()) + a.updateHeader() + // Disable indexed navigation during key evaluation (GoTo must use natural order) a.idxState.current = -1 diff --git a/hbrdd/ntx/build.go b/hbrdd/ntx/build.go index 00891a5..22e6279 100644 --- a/hbrdd/ntx/build.go +++ b/hbrdd/ntx/build.go @@ -100,7 +100,7 @@ func CreateIndex(path string, keyExpr string, keyLen int, unique bool, descend b seps[j].recNo = binary.LittleEndian.Uint32(childPg[lastOff+4 : lastOff+8]) seps[j].key = make([]byte, keyLen) copy(seps[j].key, childPg[lastOff+8:lastOff+8+keyLen]) - // Only remove from leaf pages — interior separators stay + // Remove from leaf only (interior separators stay as routing keys) if isLeafLevel { binary.LittleEndian.PutUint16(childPg[0:2], uint16(childCnt-1)) }