Files
TeslaRel410/BORLAND/BDE/EXAMPLES/PASCAL/TBLLOCK.PAS
T
CydandClaude Fable 5 63312e07f9 source410: literal 4.10 source reconstruction + BC++ 4.52 fleet toolchain archived
- BORLAND/: Borland C++ 4.52 (chosen over 4.5 by byte-match: CODE/RP/CW32.LIB
  is identical to 4.52's install lib). BCC32/TLINK32/TLIB/MAKE run natively on
  Win11; CODE/BT/OPT.MAK is the shipped BTL4OPT.EXE's exact flag recipe
  (extender = Borland PowerPack DPMI32, not Phar Lap TNT).
- restoration/source410/: the literal 1995-form reconstruction of the missing
  BT game source (never mixed into CODE/). Round 1-3 state:
  * 6 of 10 surviving original TUs COMPILE CLEAN under the period toolchain
    (BTMSSN, BTCNSL, BTSCNRL, BTTEAM, BTL4MODE, BTL4ARND) - first builds
    since 1996.
  * BT_L4/BTL4APP.CPP pilot reconstruction: 12/12 functions, Fail() lands on
    its binary-recorded line 400 exactly.
  * BT/BTCNSL.HPP: console wire IDs recovered from the binary's ctors
    (Killed=9, Damaged=10, ScoreUpdate=13, DeathWithoutHonor=15 [T1];
    TeamScore=12 flagged [T4]).
  * MUNGA/: 8 engine-header backfills back-dated from the BT412 WinTesla tree
    (VDATA numbering decomp-verified; AUDREND's OpenAL-era virtual removed -
    the period compiler is the drift detector).
  * Tooling: backdate.py (WinTesla->1995 header transform), compile410.sh
    (per-TU verification sweep under authentic OPT.MAK flags).
  * README: corrected roadmap - MECH.HPP is the capstone grown with the mech
    TU reconstructions; BTREG.CPP green = the header-family milestone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 07:33:26 -05:00

191 lines
7.3 KiB
ObjectPascal

{ tbllock.pas }
program TblLock;
{$IfDef VER80}
uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs,
DbiProcs, DbiTypes, DbiErrs;
{$Else}
uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs,
SnipTool, SnipData;
{$EndIf}
const
szTblName = 'customer'; { Name of table to be created. }
szTblType = szPARADOX; { Table type to use. }
{=====================================================================
Function:
TblLock();
Description:
This example shows how to lock a table. The
example will simulate Multi-user access by adding sessions.
The example will show both working and failing locks.
===================================================================== }
var
rslt: DBIResult; { Value returned from IDAPI functions }
TblProps: CURProps; { Properties of the table. Used to determine
the size of the record. }
hDb1: hDBIDb; { Handle to the first database }
hCur1: hDBICur; { Handle to the first table }
hSession1: hDBISes; { Handle to the first session }
pRecBuf1: pBYTE; { Pointer to the record buffer }
hDb2: hDBIDb; { Handle to the second database }
hCur2: hDBICur; { Handle to the second table }
hSession2: hDBISes; { Handle to the second session }
pRecBuf2: pBYTE; { Pointer to the record buffer }
begin
Screen('*** Table Locking Example ***');
Screen(' Initializing IDAPI...');
if (InitAndConnect(hDb1) <> DBIERR_NONE) then { Terminate example if }
begin { Initialization fails }
Screen('');
Screen('*** End of Example ***');
exit;
end;
{ Acquire a session handle. Initializing IDAPI opens a session. }
Screen(' Acquiring the current sessions handle...');
ChkRslt(DbiGetCurrSession(hSession1), DBIERR_NONE,
' Error - GetCurrSession.');
Screen(' Setting the Database directory in session #1...');
ChkRslt(DbiSetDirectory(hDb1, pCHAR(szTblDirectory)), DBIERR_NONE,
' Error - SetDirectory.');
Screen(' Opening the '+szTblName+' Table in session #1...');
if (ChkRslt(DbiOpenTable(hDb1, pCHAR(szTblName), pCHAR(szTblType),
nil, nil, 0, dbiREADWRITE,
dbiOPENSHARED, xltFIELD, FALSE, nil, hCur1),
DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then
begin
Screen('');
Screen(' Close the first database handle...');
CloseDbAndexit(hDb1);
Screen('');
Screen('*** End of example ***');
exit;
end;
Screen(' Place a write lock on the table in session #1...');
ChkRslt(DbiAcqTableLock(hCur1, dbiWRITELOCK), DBIERR_NONE,
' Error - AcqTableLock.');
{ Aquire a new session. This is to simulate multi-user table access. }
Screen('');
Screen(' Opening session #2...');
ChkRslt(DbiStartSession('', hSession2, nil), DBIERR_NONE,
' Error - StartSession.');
Screen('');
Screen(' Opening Standard Database in session #2...');
if (ChkRslt(DbiOpenDatabase('', nil, dbiREADWRITE, dbiOPENSHARED,
nil, 0, nil, nil, hDb2),
DBIERR_NONE, ' Error - OpenDatabase.')
<> DBIERR_NONE) then
begin
Screen('');
Screen(' Close the first cursor to the table...');
ChkRslt(DbiCloseCursor(hCur1), DBIERR_NONE,
' Error - CloseCursor.');
Screen(' Close the first database handle...');
CloseDbAndExit(hDb1);
exit;
end;
Screen(' Setting the Database directory in session #2...');
ChkRslt(DbiSetDirectory(hDb2, pCHAR(szTblDirectory)), DBIERR_NONE,
' Error - SetDirectory.');
Screen(' Opening the '+szTblName+' Table in session #2...');
if (ChkRslt(DbiOpenTable(hDb2, pCHAR(szTblName), pCHAR(szTblType),
nil, nil, 0, dbiREADWRITE,
dbiOPENSHARED, xltFIELD, FALSE, nil, hCur2),
DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then
begin
Screen('');
Screen(' Close the first cursor to the table...');
ChkRslt(DbiCloseCursor(hCur1), DBIERR_NONE,
' Error - CloseCursor.');
Screen(' Close the first database handle...');
ChkRslt(DbiCloseDatabase(hDb1), DBIERR_NONE,
' Error - CloseDatabase.');
Screen(' Close the second database handle...');
ChkRslt(DbiCloseDatabase(hDb2), DBIERR_NONE,
' Error - CloseDatabase.');
Screen(' Exit IDAPI...');
ChkRslt(DbiExit, DBIERR_NONE, ' Error - Exit.');
exit;
end;
ChkRslt(DbiGetCursorProps(hCur2, TblProps), DBIERR_NONE,
' Error - GetCursorProps.');
{ create the record buffer. }
GetMem(pRecBuf1, TblProps.iRecBufSize * sizeof(BYTE));
GetMem(pRecBuf2, TblProps.iRecBufSize * sizeof(BYTE));
{ Initialize the record buffer }
ChkRslt(DbiInitRecord(hCur2, pRecBuf2), DBIERR_NONE,
' Error - InitRecord.');
{ Go to the top of the Table }
ChkRslt(DbiSetToBegin(hCur2), DBIERR_NONE, ' Error - SetToBegin.');
Screen(' Session #2 is getting and locking the first record...');
Screen(' Error expected - table is locked...');
ChkRslt(DbiGetNextRecord(hCur2, dbiWRITELOCK, pRecBuf2, nil),
DBIERR_NONE, ' Error - GetRecord.');
Screen(' Session #2 is getting the first record without locking...');
ChkRslt(DbiGetNextRecord(hCur2, dbiNOLOCK, pRecBuf2, nil),
DBIERR_NONE, ' Error - GetRecord.');
Screen('');
Screen(' Session #2 is attempting to modify the record...');
Screen(' Error Expected - table is locked...');
ChkRslt(DbiModifyRecord(hCur2, pRecBuf2, TRUE),
DBIERR_NONE, ' Error - ModifyRecord.');
{ Clean Up }
FreeMem(pRecBuf1, TblProps.iRecBufSize * sizeof(BYTE));
FreeMem(pRecBuf2, TblProps.iRecBufSize * sizeof(BYTE));
ChkRslt(DbiSetCurrSession(hSession2), DBIERR_NONE,
' Error - SetCurrSession.');
Screen('');
Screen(' Close the cursor to the table in session #2...');
ChkRslt(DbiCloseCursor(hCur2), DBIERR_NONE,
' Error - CloseCursor.');
Screen(' Close the database handle in session #2...');
ChkRslt(DbiCloseDatabase(hDb2), DBIERR_NONE,
' Error - CloseDatabase.');
Screen(' Closing session #2...');
ChkRslt(DbiCloseSession(hSession2), DBIERR_NONE,
' Error - CloseSession.');
ChkRslt(DbiSetCurrSession(hSession1), DBIERR_NONE,
' Error - SetCurrSession.');
ChkRslt(DbiRelTableLock(hCur1, TRUE, dbiWRITELOCK), DBIERR_NONE,
' Error - RelTableLock.');
{ Close the cursor in session #1 }
Screen('');
ChkRslt(DbiCloseCursor(hCur1), DBIERR_NONE,
' Error - CloseCursor.');
Screen(' Close the Database and exit IDAPI...');
CloseDbAndexit(hDb1);
Screen('*** End of Example ***');
end.