Files
TeslaRel410/BORLAND/BDE/EXAMPLES/SNIPIT/TBLLOCK.C
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

182 lines
6.4 KiB
C++

// BDE - (C) Copyright 1995 by Borland International
// tbllock.c
#include "snipit.h"
static const char szTblName[] = "customer";
static const char szTblType[] = szPARADOX;
//=====================================================================
// Function:
// TblLock();
//
// Description:
// This example shows how to lock a table. The
// example will simulate multi-user access by opening a table from
// multiple sessions. The example will show both working and
// failing locks.
//=====================================================================
void
TblLock (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("*** Table 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;
}
Screen(" Place a write lock on the table in session #1...");
rslt = DbiAcqTableLock(hCur1, dbiWRITELOCK);
ChkRslt(rslt, "AcqTableLock");
// Create a new session 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 buffer.
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 = 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");
// Go to the top of the table.
rslt = DbiSetToBegin(hCur2);
ChkRslt(rslt, "SetToBegin");
Screen(" Session #2 is getting and locking the first record...");
Screen(" Error expected - file is locked...");
rslt = DbiGetNextRecord(hCur2, dbiWRITELOCK, pRecBuf2, NULL);
ChkRslt(rslt, "GetRecord");
Screen("\r\n Session #2 is getting the first record without locking...");
rslt = DbiGetNextRecord(hCur2, dbiNOLOCK, pRecBuf2, NULL);
ChkRslt(rslt, "GetRecord");
Screen("\r\n Session #2 is attempting to modify the record...");
Screen(" Error expected - file is locked...");
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 cursor to the table in session #2...");
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");
rslt = DbiRelTableLock(hCur1, TRUE, dbiWRITELOCK);
ChkRslt(rslt, "RelTableLock");
Screen("\r\n Close the cursor to the table in session #1...");
rslt = DbiCloseCursor(&hCur1);
ChkRslt(rslt, "CloseCursor");
Screen(" Close the database and exit IDAPI...");
CloseDbAndExit(&hDb1);
Screen("\r\n*** End of Example ***");
}