- 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>
192 lines
6.8 KiB
C++
192 lines
6.8 KiB
C++
// BDE - (C) Copyright 1995 by Borland International
|
|
|
|
// reclock.c
|
|
#include "snipit.h"
|
|
|
|
static const char szTblName[] = "cust";
|
|
static const char szTblType[] = szDBASE;
|
|
|
|
//=====================================================================
|
|
// Function:
|
|
// RecLock();
|
|
//
|
|
// Description:
|
|
// This example shows how to do record locking. The
|
|
// example will simulate multi-user access by creating multiple
|
|
// sessions. The example will show both working and failing locks.
|
|
//=====================================================================
|
|
void
|
|
RecLock (void)
|
|
{
|
|
DBIResult rslt; // Value returned from IDAPI functions
|
|
CURProps TblProps; // Properties of the table. Used to determine
|
|
// the size of the record
|
|
hDBIDb hDb1; // Handle to the first database
|
|
hDBICur hCur1; // Handle to the first table
|
|
hDBISes hSession1; // Handle to the first session
|
|
pBYTE pRecBuf1; // Pointer to the record buffer
|
|
hDBIDb hDb2; // Handle to the second database
|
|
hDBICur hCur2; // Handle to the second table
|
|
hDBISes hSession2; // Handle to the second session
|
|
pBYTE pRecBuf2; // Pointer to the record buffer
|
|
|
|
Screen("*** Record Locking Example ***\r\n");
|
|
|
|
BREAK_IN_DEBUGGER();
|
|
|
|
Screen(" Initializing IDAPI...\r\n");
|
|
if (InitAndConnect(&hDb1) != DBIERR_NONE)
|
|
{
|
|
Screen("\r\n*** End of Example ***");
|
|
return;
|
|
}
|
|
|
|
// Acquire a session handle. Initializing IDAPI opens a session.
|
|
Screen(" Acquiring the current session's handle...");
|
|
rslt = DbiGetCurrSession(&hSession1);
|
|
ChkRslt(rslt, "GetCurrSession");
|
|
|
|
Screen(" Setting the database directory in session #1...");
|
|
rslt = DbiSetDirectory(hDb1, (pCHAR) szTblDirectory);
|
|
ChkRslt(rslt, "SetDirectory");
|
|
|
|
Screen(" Opening the %s table in session #1...", szTblName);
|
|
rslt = DbiOpenTable(hDb1, (pCHAR) szTblName, (pCHAR) szTblType,
|
|
NULL, NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
|
|
xltFIELD, FALSE, NULL, &hCur1);
|
|
if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
|
|
{
|
|
CloseDbAndExit(&hDb1);
|
|
Screen("\r\n*** End of Example ***");
|
|
return;
|
|
}
|
|
|
|
// Aquire a new session. This is to simulate multi-user table access.
|
|
Screen("\r\n Opening session #2...");
|
|
rslt = DbiStartSession("", &hSession2, NULL);
|
|
ChkRslt(rslt, "StartSession");
|
|
|
|
Screen("\r\n Opening standard database in session #2...");
|
|
rslt = DbiOpenDatabase("", 0, dbiREADWRITE, dbiOPENSHARED,
|
|
NULL, NULL, NULL, NULL, &hDb2);
|
|
if (ChkRslt(rslt, "OpenDatabase") != DBIERR_NONE)
|
|
{
|
|
rslt = DbiCloseCursor(&hCur1);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
CloseDbAndExit(&hDb1);
|
|
Screen("\r\n*** End of Example ***");
|
|
return;
|
|
}
|
|
|
|
Screen(" Setting the database directory in session #2...");
|
|
rslt = DbiSetDirectory(hDb2, (pCHAR) szTblDirectory);
|
|
ChkRslt(rslt, "SetDirectory");
|
|
|
|
Screen(" Opening the %s table in session #2...", szTblName);
|
|
rslt = DbiOpenTable(hDb2, (pCHAR) szTblName, (pCHAR) szTblType,
|
|
NULL, NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
|
|
xltFIELD, FALSE, NULL, &hCur2);
|
|
if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
|
|
{
|
|
rslt = DbiCloseCursor(&hCur1);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
rslt = DbiCloseDatabase(&hDb2);
|
|
ChkRslt(rslt, "CloseDatabase");
|
|
CloseDbAndExit(&hDb1);
|
|
Screen("\r\n*** End of Example ***");
|
|
return;
|
|
}
|
|
|
|
// Create the record buffers.
|
|
rslt = DbiGetCursorProps(hCur2, &TblProps);
|
|
ChkRslt(rslt, "GetCursorProps");
|
|
|
|
pRecBuf1 = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
|
|
pRecBuf2 = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
|
|
if ((!pRecBuf1) || (!pRecBuf2))
|
|
{
|
|
if (pRecBuf1) free(pRecBuf1);
|
|
if (pRecBuf2) free(pRecBuf2);
|
|
rslt = DbiCloseCursor(&hCur1);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
rslt = DbiCloseCursor(&hCur2);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
rslt = DbiCloseDatabase(&hDb2);
|
|
ChkRslt(rslt, "CloseDatabase");
|
|
CloseDbAndExit(&hDb1);
|
|
Screen("\r\n*** End of Example ***");
|
|
return;
|
|
}
|
|
|
|
// Initialize the record buffer.
|
|
rslt = DbiInitRecord(hCur2, pRecBuf2);
|
|
ChkRslt(rslt, "InitRecord");
|
|
|
|
Screen(" Session #2 is getting and locking the first record...");
|
|
rslt = DbiSetToBegin(hCur2);
|
|
ChkRslt(rslt, "SetToBegin");
|
|
rslt = DbiGetNextRecord(hCur2, dbiWRITELOCK, pRecBuf2, NULL);
|
|
ChkRslt(rslt, "GetRecord");
|
|
|
|
// Set the current session to session #1.
|
|
rslt = DbiSetCurrSession(hSession1);
|
|
ChkRslt(rslt, "SetCurrSession");
|
|
|
|
Screen("\r\n Session #1 is getting the first record without"
|
|
" locking it...");
|
|
rslt = DbiSetToBegin(hCur1);
|
|
ChkRslt(rslt, "SetToBegin");
|
|
rslt = DbiGetNextRecord(hCur1, dbiNOLOCK, pRecBuf1, NULL);
|
|
ChkRslt(rslt, "GetRecord");
|
|
|
|
// Attempt to modify the record in session #1 - get an error as
|
|
// session #2 has the record locked.
|
|
Screen(" Session #1 is modifying the record...");
|
|
Screen(" Error Expected - record is locked...");
|
|
rslt = DbiModifyRecord(hCur1, pRecBuf1, TRUE);
|
|
ChkRslt(rslt, "GetRecord");
|
|
|
|
// Switch the current session to session #2.
|
|
rslt = DbiSetCurrSession(hSession2);
|
|
ChkRslt(rslt, "SetCurrSession");
|
|
|
|
// Modify the record in session #2. Session #2 locked the record,
|
|
// so it will succeed this time. Note that the lock is released
|
|
// after the record is modified.
|
|
Screen("\r\n Session #2 is modifying the record...");
|
|
rslt = DbiModifyRecord(hCur2, pRecBuf2, TRUE);
|
|
ChkRslt(rslt, "ModifyRecord");
|
|
|
|
// Clean Up
|
|
free(pRecBuf1);
|
|
free(pRecBuf2);
|
|
|
|
rslt = DbiSetCurrSession(hSession2);
|
|
ChkRslt(rslt, "SetCurrSession");
|
|
|
|
Screen("\r\n Close the %s table in session #2...", szTblName);
|
|
rslt = DbiCloseCursor(&hCur2);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
|
|
Screen(" Close the database handle in session #2...");
|
|
rslt = DbiCloseDatabase(&hDb2);
|
|
ChkRslt(rslt, "CloseDatabase");
|
|
|
|
Screen(" Closing session #2...");
|
|
rslt = DbiCloseSession(hSession2);
|
|
ChkRslt(rslt, "CloseSession");
|
|
|
|
rslt = DbiSetCurrSession(hSession1);
|
|
ChkRslt(rslt, "SetCurrSession");
|
|
|
|
Screen("\r\n Close the %s table in session #1...", szTblName);
|
|
rslt = DbiCloseCursor(&hCur1);
|
|
ChkRslt(rslt, "CloseCursor");
|
|
|
|
Screen(" Close the database and exit IDAPI...");
|
|
CloseDbAndExit(&hDb1);
|
|
|
|
Screen("\r\n*** End of Example ***");
|
|
}
|
|
|