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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // cr8pxtbl.c
  4. #include "snipit.h"
  5.  
  6. static const char szTblName[] = "CR8PXTBL";
  7. static const char szTblType[] = szPARADOX;
  8.  
  9. // Field descriptor used in creating a table.
  10. static SNIPFAR FLDDesc fldDesc[] = {
  11.               { // Field 1 - AUTOINC
  12.                 1,            // Field number
  13.                 "AUTOINC",    // Field name
  14.                 fldINT32,     // Field type
  15.                 fldstAUTOINC, // Field subtype
  16.                 0,            // Field size
  17.                 0,            // Decimal places   ( 0 )
  18.                               //     computed
  19.                 0,            // Offset in record ( 0 )
  20.                 0,            // Length in bytes  ( 0 )
  21.                 0,            // For Null bits    ( 0 )
  22.                 fldvNOCHECKS, // Validity checks  ( 0 )
  23.                 fldrREADWRITE // Rights
  24.               },
  25.               { // Field 2 - ALPHA
  26.                 2, "ALPHA", fldZSTRING, fldUNKNOWN,
  27.                 10, 0, 0, 0, 0,
  28.                 fldvNOCHECKS, fldrREADWRITE
  29.               },
  30.               { // Field 3 - NUMERIC
  31.                 3, "NUMERIC", fldFLOAT, fldUNKNOWN,
  32.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  33.               },
  34.               { // Field 5 - MONEY
  35.                 4, "MONEY", fldFLOAT, fldstMONEY,
  36.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  37.               },
  38.               { // Field 4 - DATE
  39.                 5, "DATE", fldDATE, fldUNKNOWN,
  40.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  41.               },
  42.               { // Field 4 - SHORT
  43.                 6, "SHORT", fldINT16, fldUNKNOWN,
  44.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  45.               },
  46.               { // Field 7 - TIME
  47.                 7, "TIME", fldTIME, fldUNKNOWN,
  48.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  49.               },
  50.               { // Field 8 - TIMESTAMP
  51.                 8, "TIMESTAMP", fldTIMESTAMP, fldUNKNOWN,
  52.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  53.               },
  54.               { // Field 9 - LONG
  55.                 9, "LONG", fldINT32, fldUNKNOWN,
  56.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  57.               },
  58.               { // Field 10 - BOOL
  59.                 10, "BOOL", fldBOOL, fldUNKNOWN,
  60.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  61.               },
  62.               { // Field 11 - BYTES
  63.                 11, "BYTES", fldBYTES, fldUNKNOWN,
  64.                 20, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  65.               },
  66.               { // Field 12 - BCD
  67.                 12, "BCD", fldBCD, fldUNKNOWN,
  68.                 32, 5, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  69.               },
  70.               { // Field 13 - MEMO
  71.                 13, "MEMO", fldBLOB, fldstMEMO,
  72.                 20, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  73.               },
  74.               { // Field 14 - BINARYBLOB
  75.                 14, "BINARYBLOB", fldBLOB, fldstBINARY,
  76.                 20, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  77.               },
  78.               { // Field 15 - FMTMEMO
  79.                 15, "FMTMEMO", fldBLOB, fldstFMTMEMO,
  80.                 20, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  81.               },
  82.               { // Field 16 - OLEOBJ
  83.                 16, "OLEOBJ", fldBLOB, fldstOLEOBJ,
  84.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  85.               },
  86.               { // Field 17 - GRAPHIC
  87.                 17, "GRAPHIC", fldBLOB, fldstGRAPHIC,
  88.                 0, 0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  89.               }
  90.              }; // Array of field descriptors.
  91.  
  92. // The number of fields in the table.
  93. static const unsigned uNumFields = sizeof(fldDesc) / sizeof (fldDesc[0]);
  94.  
  95. //=====================================================================
  96. //  Function:
  97. //          CreateAndFillSamplePX();
  98. //
  99. //  Description:
  100. //          This sample code will create a Paradox table, append
  101. //          10 records to the table, and then delete the table.
  102. //
  103. //  Note:   The new Paradox 5.0 field types are used as part of this
  104. //          example. Because of this, the table generated by this
  105. //          example cannot be viewed in Paradox 4.5.
  106. //=====================================================================
  107. void
  108. CreateAndFillSamplePX (void)
  109. {
  110.     hDBIDb      hDb;                // Handle to the database
  111.     hDBICur     hCur;               // Handle to the table
  112.     CRTblDesc   TblDesc;            // Create table descriptor
  113.     UINT16      uDispNumRecs = 10 ; // Number of records to add and
  114.                                     // display.
  115.     DBIResult   rslt;               // Return value from IDAPI functions
  116.  
  117.     Screen("*** Create/Open/Fill Paradox Table Example ***\r\n");
  118.  
  119.     BREAK_IN_DEBUGGER();
  120.  
  121.     Screen("    Initializing IDAPI...");
  122.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  123.     {
  124.         Screen("\r\n*** End of Example ***");
  125.         return;
  126.     }
  127.  
  128.     Screen("    Setting the database directory...");
  129.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  130.     ChkRslt(rslt, "SetDirectory");
  131.  
  132.     Screen("    Initializing the table descriptor...");
  133.     memset((void *) &TblDesc , 0, sizeof(CRTblDesc));
  134.     lstrcpy(TblDesc.szTblName, szTblName);
  135.     lstrcpy(TblDesc.szTblType, szTblType);
  136.     TblDesc.iFldCount = uNumFields;
  137.     TblDesc.pfldDesc = fldDesc;
  138.  
  139.     Screen("    Creating the %s Paradox table...", szTblName);
  140.     rslt = DbiCreateTable(hDb, TRUE, &TblDesc);
  141.     if (ChkRslt(rslt, "CreateTable") != DBIERR_NONE)
  142.     {
  143.         CloseDbAndExit(&hDb);
  144.         Screen("\r\n*** End of Example ***");
  145.         return;
  146.     }            
  147.  
  148.     Screen("    Fill the %s table with random data...", szTblName);
  149.     FillTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType, uDispNumRecs);
  150.  
  151.     Screen("    Open the %s table...", szTblName);
  152.     rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType,
  153.                         NULL, NULL, 0, dbiREADWRITE, dbiOPENSHARED,
  154.                         xltFIELD, FALSE, NULL, &hCur);
  155.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  156.     {
  157.         rslt = DbiDeleteTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType);
  158.         ChkRslt(rslt, "DeleteTable");
  159.         CloseDbAndExit(&hDb);
  160.         Screen("\r\n*** End of Example ***");
  161.         return;
  162.     }
  163.  
  164.     Screen("    Display the %s table...", szTblName);
  165.     DisplayTable(hCur, uDispNumRecs);
  166.  
  167.     Screen("\r\n    Close the %s table...", szTblName);
  168.     rslt = DbiCloseCursor(&hCur);
  169.     ChkRslt(rslt, "CloseCursor");
  170.  
  171.     Screen("    Deleting the %s table...", szTblName);
  172.     rslt = DbiDeleteTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType);
  173.     ChkRslt(rslt, "DeleteTable");
  174.  
  175.     Screen("    Close the database and exit IDAPI...");
  176.     CloseDbAndExit(&hDb);
  177.  
  178.     Screen("\r\n*** End of Example ***");
  179. }
  180.  
  181.