diff --git a/_FiveSql2/src/TSqlIndex.prg b/_FiveSql2/src/TSqlIndex.prg index bfe3904..257576d 100644 --- a/_FiveSql2/src/TSqlIndex.prg +++ b/_FiveSql2/src/TSqlIndex.prg @@ -132,23 +132,34 @@ RETURN nWA METHOD FindExclusive( cTableLow ) CLASS TSqlIndex - /* Pre-flight exclusive-lock detection. - * Originally used dbInfo(DBI_FULLPATH)/DBI_SHARED to scan open - * workareas for an exclusive hold on the target DBF. In Five, - * `dbInfo()` is stubbed (returns NIL) and the DBI_* symbols are - * unresolved at compile time → runtime panic the moment any - * workarea is Used() when this runs (standalone PRGs routinely - * dbUseArea before calling five_SQL, so they tripped this). + /* Scan all used workareas for an exclusive hold on cTableLow. + * Returns the conflicting workarea number, or 0 if the table + * is free to open. * - * The check cannot function correctly on Five regardless, so - * we short-circuit to 0 (= no conflict). Matches behavior of - * the 43-test harness which only reaches here with no Used - * workareas, so the net behavior is preserved. - * - * Future: when dbInfo(DBI_FULLPATH) lands in hbrtl, restore - * the scan. Until then use `Alias()` + filename matching if - * exclusive-lock preflight becomes necessary. + * Fully functional now that hbrtl implements dbInfo(DBI_FULLPATH) + * and DBI_SHARED. The DBI_* constants resolve via include/dbinfo.ch. */ + LOCAL nSaved, nArea, cDbfName, lShared + + nSaved := Select() + + FOR nArea := 1 TO 250 + IF ( nArea )->( Used() ) + dbSelectArea( nArea ) + IF ! Empty( Alias() ) + cDbfName := Lower( AllTrim( dbInfo( DBI_FULLPATH ) ) ) + IF cTableLow + ".dbf" $ cDbfName .OR. cTableLow $ cDbfName + lShared := dbInfo( DBI_SHARED ) + IF lShared == .F. + dbSelectArea( nSaved ) + RETURN nArea + ENDIF + ENDIF + ENDIF + ENDIF + NEXT + + dbSelectArea( nSaved ) RETURN 0