home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bde / snipit.pak / RDOLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  3.7 KB  |  101 lines

  1. // BDE - (C) Copyright 1995 by Borland International;
  2.  
  3. // rdolock.c
  4. #include "snipit.h"
  5.  
  6. static const char szTblName[] = "customer";
  7. static const char szTblType[] = szPARADOX;
  8.  
  9. //=====================================================================
  10. //  Function:
  11. //          RdoLock();
  12. //
  13. //  Description:
  14. //          This example shows how to make a directory read-only. A
  15. //          directory is made read-only by calling the DbiAcqPersistTableLock
  16. //          function with the fully qualified path name of the directory
  17. //          to lock.  The filename that is locked is PARADOX.DRO, which
  18. //          IDAPI interprets as making the directory read-only (no file
  19. //          named PARADOX.DRO should exist.)
  20. //
  21. //  Note:   Local share needs to be set to "TRUE" in IDAPI.CFG in order
  22. //          for this example to work.
  23. //=====================================================================
  24. void
  25. RdoLock (void)
  26. {
  27.     DBIResult   rslt;       // Value returned from IDAPI functions
  28.     hDBIDb      hDb;        // Handle to the database
  29.     hDBICur     hCur;       // Handle to the table
  30.     DBIPATH     szLockName; // Contains the read-only lock
  31.  
  32.     Screen("*** Making a directory read-only ***\r\n");
  33.  
  34.     BREAK_IN_DEBUGGER();
  35.  
  36.     Screen("    Initializing IDAPI...\r\n");
  37.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  38.     {                                        
  39.         Screen("\r\n*** End of Example ***");
  40.         return;
  41.     }
  42.  
  43.     Screen("    Setting the database directory...");    
  44.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  45.     ChkRslt(rslt, "SetDirectory");
  46.  
  47.     // Specify the directory to lock.
  48.     strcpy(szLockName, szTblDirectory);
  49.     // Name of the directory lock.
  50.     strcat(szLockName, "\\paradox.dro");
  51.  
  52.     // Mark the directory as read only. Note that the type of the
  53.     //   lock has to be set to "PARADOX".
  54.     rslt = DbiAcqPersistTableLock(hDb, szLockName, (pCHAR) szTblType);
  55.     ChkRslt(rslt, "AcqPersistTableLock");
  56.  
  57.     Screen("    Opening the %s table for Read/Write...", szTblName);
  58.     Screen("        Expect error - directory read only...");
  59.     rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType,
  60.                         NULL, NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
  61.                         xltFIELD, FALSE, NULL, &hCur);
  62.     if (ChkRslt(rslt, "OpenTable") == DBIERR_NONE)
  63.     {
  64.         Screen("        Table opened in Read/Write mode - make certain local"
  65.                " share is TRUE in IDAPI.CFG\r\n"
  66.                "            in order to make a local directory read-only");
  67.         rslt = DbiCloseCursor(&hCur);
  68.         ChkRslt(rslt, "CloseCursor");
  69.     }
  70.  
  71.     Screen("\r\n    Opening the %s table for read-only...", szTblName);
  72.     rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType,
  73.                         NULL, NULL, NULL, dbiREADONLY, dbiOPENSHARED,
  74.                         xltFIELD, FALSE, NULL, &hCur);
  75.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  76.     {
  77.         rslt = DbiRelPersistTableLock(hDb, szLockName, (pCHAR) szTblType);
  78.         ChkRslt(rslt, "    RelPersistTableLock");
  79.         CloseDbAndExit(&hDb);
  80.         Screen("\r\n*** End of Example ***");
  81.         return;
  82.     }
  83.  
  84.     Screen("    Display the first ten records in the table...");
  85.     DisplayTable(hCur, 10);
  86.  
  87.     Screen("\r\n    Close the %s table...", szTblName);
  88.     rslt = DbiCloseCursor(&hCur);
  89.     ChkRslt(rslt, "CloseCursor");
  90.  
  91.     // Release the read-only lock on the directory.
  92.     rslt = DbiRelPersistTableLock(hDb, szLockName, (pCHAR) szTblType);
  93.     ChkRslt(rslt, "RelPersistTableLock");
  94.  
  95.     Screen("    Close the database and exit IDAPI...");
  96.     CloseDbAndExit(&hDb);
  97.  
  98.     Screen("\r\n*** End of Example ***");
  99. }
  100.  
  101.