// BDE - (C) Copyright 1995 by Borland International; // rdolock.c #include "snipit.h" static const char szTblName[] = "customer"; static const char szTblType[] = szPARADOX; //===================================================================== // Function: // RdoLock(); // // Description: // This example shows how to make a directory read-only. A // directory is made read-only by calling the DbiAcqPersistTableLock // function with the fully qualified path name of the directory // to lock. The filename that is locked is PARADOX.DRO, which // IDAPI interprets as making the directory read-only (no file // named PARADOX.DRO should exist.) // // Note: Local share needs to be set to "TRUE" in IDAPI.CFG in order // for this example to work. //===================================================================== void RdoLock (void) { DBIResult rslt; // Value returned from IDAPI functions hDBIDb hDb; // Handle to the database hDBICur hCur; // Handle to the table DBIPATH szLockName; // Contains the read-only lock Screen("*** Making a directory read-only ***\r\n"); BREAK_IN_DEBUGGER(); Screen(" Initializing IDAPI...\r\n"); if (InitAndConnect(&hDb) != DBIERR_NONE) { Screen("\r\n*** End of Example ***"); return; } Screen(" Setting the database directory..."); rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory); ChkRslt(rslt, "SetDirectory"); // Specify the directory to lock. strcpy(szLockName, szTblDirectory); // Name of the directory lock. strcat(szLockName, "\\paradox.dro"); // Mark the directory as read only. Note that the type of the // lock has to be set to "PARADOX". rslt = DbiAcqPersistTableLock(hDb, szLockName, (pCHAR) szTblType); ChkRslt(rslt, "AcqPersistTableLock"); Screen(" Opening the %s table for Read/Write...", szTblName); Screen(" Expect error - directory read only..."); rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType, NULL, NULL, NULL, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur); if (ChkRslt(rslt, "OpenTable") == DBIERR_NONE) { Screen(" Table opened in Read/Write mode - make certain local" " share is TRUE in IDAPI.CFG\r\n" " in order to make a local directory read-only"); rslt = DbiCloseCursor(&hCur); ChkRslt(rslt, "CloseCursor"); } Screen("\r\n Opening the %s table for read-only...", szTblName); rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType, NULL, NULL, NULL, dbiREADONLY, dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur); if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE) { rslt = DbiRelPersistTableLock(hDb, szLockName, (pCHAR) szTblType); ChkRslt(rslt, " RelPersistTableLock"); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } Screen(" Display the first ten records in the table..."); DisplayTable(hCur, 10); Screen("\r\n Close the %s table...", szTblName); rslt = DbiCloseCursor(&hCur); ChkRslt(rslt, "CloseCursor"); // Release the read-only lock on the directory. rslt = DbiRelPersistTableLock(hDb, szLockName, (pCHAR) szTblType); ChkRslt(rslt, "RelPersistTableLock"); Screen(" Close the database and exit IDAPI..."); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); }