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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // batmove.c
  4. #include "snipit.h"
  5.  
  6. #define NAMELEN  10 // Length of the name fields.
  7. #define PLACELEN 20 // Length of the POB field.
  8. #define DATELEN  11 // Display length for a date field: mm\dd\yyyy.
  9.  
  10. static const char szDBTblName[] = "DBPeople";
  11. static const char szDBTblType[] = szDBASE;
  12.  
  13. // Field descriptor used in creating a table.
  14. static SNIPFAR FLDDesc DBfldDesc[] = {
  15.                           { // Field 1 - First Name
  16.                             1,            // Field number
  17.                             "Name",       // Field name
  18.                             fldZSTRING,   // Field type
  19.                             fldUNKNOWN,   // Field subtype
  20.                             NAMELEN,      // Field size ( 1 or 0, except
  21.                                           //     BLOB or CHAR field )
  22.                             0,            // Decimal places ( 0 )
  23.                                           //     computed
  24.                             0,            // Offset in record ( 0 )
  25.                             0,            // Length in bytes  ( 0 )
  26.                             0,            // For NULL bits    ( 0 )
  27.                             fldvNOCHECKS, // Validity checks   ( 0 )
  28.                             fldrREADWRITE // Rights
  29.                           },
  30.                           { // Field 2 - Place of Birth
  31.                             2, "POB", fldZSTRING, fldUNKNOWN, PLACELEN,
  32.                             0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  33.                           },
  34.                           { // Field 3 - Date of Birth
  35.                             3, "DOB", fldZSTRING, fldUNKNOWN, DATELEN,
  36.                             0, 0, 0, 0, fldvNOCHECKS, fldrREADWRITE
  37.                           }                  
  38.                      };  // Array of field descriptors
  39.  
  40. // Index descriptor - describes the index associated with the
  41. // table. 
  42. static SNIPFAR IDXDesc DBidxDesc[] = {
  43.                     {  // Primary Index - Full Name
  44.                        "Name",      // Name
  45.                        1,           // Number
  46.                        {"NAME"},    // Tag name ( for dBase )
  47.                        { NULL },    // Optional format ( BTREE,
  48.                                     //   HASH, etc )
  49.                        FALSE,       // Primary?
  50.                        FALSE,       // Unique?
  51.                        FALSE,       // Descending?
  52.                        TRUE,        // Maintained?
  53.                        FALSE,       // SubSet?
  54.                        FALSE,       // Expression index?
  55.                        NULL,        // For QBE only
  56.                        1,           // Fields in key
  57.                        1,           // Length in bytes
  58.                        FALSE,       // Index out of date?
  59.                        0,           // Key type of expression
  60.                        { 1 },       // Array of field numbers
  61.                        { 0 },       // Key expression
  62.                        { 0 },       // Key condition
  63.                        FALSE,       // Case insensitive
  64.                        0,           // Block size in bytes
  65.                        0            // Restructure number
  66.                     },
  67.                     {  // Secondary index 1 - Single field
  68.                        "POB", 2, {"POB1"}, { NULL }, FALSE, FALSE, FALSE,
  69.                        TRUE, FALSE, FALSE, NULL, 1, 1, FALSE, 0, { 2 },
  70.                        { 0 }, { 0 }, FALSE, 0, 0
  71.                     },
  72.                     {  // Secondary index 2 - Single field
  73.                        "DOB", 3, {"DOB1"}, { NULL }, FALSE, FALSE, FALSE,
  74.                        TRUE, FALSE, FALSE, NULL, 1, 1, FALSE, 0, { 3 },
  75.                        { 0 }, { 0 }, FALSE, 0, 0
  76.                     }
  77.  
  78.                 };
  79.  
  80. static const char szPXTblName[] = "PXPeople";
  81. static const char szPXTblType[] = szPARADOX; 
  82.  
  83. // Field descriptor used in creating a table.
  84. static SNIPFAR FLDDesc PXfldDesc[] = {
  85.               { // Field 1 - First Name
  86.                   1,            // Field number
  87.                   "First Name", // Field name
  88.                   fldZSTRING,   // Field type
  89.                   fldUNKNOWN,   // Field subtype
  90.                   NAMELEN,      // Field size ( 1 or 0, except
  91.                                 //     BLOB or CHAR field )
  92.                   0,            // Decimal places ( 0 )
  93.                                 //     computed
  94.                   0,            // Offset in record ( 0 )
  95.                   0,            // Length in bytes  ( 0 )
  96.                   0,            // For NULL bits    ( 0 )
  97.                   fldvNOCHECKS, // Validity checks   ( 0 )
  98.                   fldrREADWRITE // Rights
  99.               },
  100.               { // Field 2 - Middle Name
  101.                   2, "Middle Name", fldZSTRING, fldUNKNOWN,
  102.                   NAMELEN, 0, 0, 0, 0,
  103.                   fldvNOCHECKS, fldrREADWRITE
  104.               },
  105.               { // Field 3 - Last Name
  106.                   3, "Last Name", fldZSTRING, fldUNKNOWN,
  107.                   NAMELEN, 0, 0, 0, 0,
  108.                   fldvNOCHECKS, fldrREADWRITE
  109.               },
  110.               { // Field 4 - Date of Birth
  111.                   4, "DOB", fldDATE, fldUNKNOWN,
  112.                   0, 0, 0, 0, 0,
  113.                   fldvNOCHECKS, fldrREADWRITE
  114.               },
  115.               { // Field 5 - Place of Birth
  116.                   5, "POB", fldZSTRING, fldUNKNOWN,
  117.                   PLACELEN, 0, 0, 0, 0,
  118.                   fldvNOCHECKS, fldrREADWRITE
  119.               }
  120.              };  // Array of field descriptors
  121.  
  122. // Index descriptor - describes the index associated with the
  123. // table. 
  124. static SNIPFAR IDXDesc PXidxDesc[] = {
  125.             { // Primary Index - Full Name
  126.                 "Full Name",  // Name
  127.                 1,            // Number
  128.                 { NULL },     // Tag name ( for dBase )
  129.                 { NULL },     // Optional format ( BTREE,
  130.                               // HASH, etc )
  131.                 TRUE,         // Primary?
  132.                 TRUE,         // Unique?
  133.                 FALSE,        // Descending?
  134.                 TRUE,         // Maintained?
  135.                 FALSE,        // Subset?
  136.                 FALSE,        // Expression index?
  137.                 NULL,         // For QBE only
  138.                 3,            // Fields in key
  139.                 1,            // Length in bytes
  140.                 FALSE,        // Index out of date?
  141.                 0,            // Key type of expression
  142.                 { 1,2,3 },    // Array of field numbers
  143.                 { 0 },        // Key expression
  144.                 { 0 },        // Key condition
  145.                 FALSE,        // Case insensitive
  146.                 0,            // Block size in bytes
  147.                 0             // Restructure number
  148.             },
  149.             { // Secondary Index 1 - Single field - Maintained,
  150.               //     Case insensitive
  151.                 "Last Name", 2, { NULL }, { NULL }, FALSE,  FALSE,  FALSE,
  152.                 TRUE, FALSE, FALSE, NULL, 1, 1, FALSE, 0, { 3 }, { 0 },
  153.                 { 0 }, TRUE, 0, 0
  154.             },
  155.             { // Secondary Index 2 - Single field - Not maintained
  156.                 "POB", 3, { NULL }, { NULL }, FALSE, FALSE, FALSE, FALSE,
  157.                 FALSE, FALSE, NULL, 1, 1, FALSE, 0, { 5 }, { 0 }, { 0 },
  158.                 FALSE, 0, 0
  159.             }
  160.         };
  161.  
  162. static DBIResult AddRecord(phDBICur hCur, pCHAR pszFirst, pCHAR pszMiddle,
  163.                            pCHAR pszLast, UINT16 iMonth, UINT16 iDay,
  164.                            UINT16 iYear, pCHAR pszPOB);
  165. static DBIResult AddRecordDB(phDBICur hCur, pCHAR pszFirst, pCHAR pszPOB,
  166.                              pCHAR pszDate);
  167.  
  168. static DBIResult CreateDBTable(phDBIDb phDb);
  169. static DBIResult CreatePXTable(phDBIDb phDb);
  170.  
  171. //=====================================================================
  172. //  Function:
  173. //          BatchMove();
  174. //
  175. //  Description:
  176. //          This example shows how to use the DbiBatchMove function to
  177. //          copy data from a Paradox table to a dBASE table.
  178. //=====================================================================
  179. void
  180. BatchMove (void)
  181. {
  182.     hDBIDb      hDb;                // Handle to the database
  183.     hDBICur     hCurDB;             // dBASE cursor handle
  184.     hDBICur     hCurPX;             // PARADOX cursor handle
  185.     UINT32      ulNumRecs = 0;      // Number of records moved in BatchMove
  186.     UINT32      ulChangedRecs = 0;  // Number of records changed in BatchMove
  187.     UINT32      ulKeyViolRecs = 0;  // Number of key violations in BatchMove
  188.     UINT32      ulProbRecs = 0;     // Number of problem recs in BatchMove
  189.     UINT16      uaSrcRecs[3] = {1,5,4}; // Fields to use in the source table
  190.     DBIResult   rslt;               // Return value from IDAPI functions
  191.     DBIPATH     szKeyViol   = "KEYVIOL";
  192.     DBIPATH     szProblems  = "PROBLEMS";
  193.     DBIPATH     szChanged   = "CHANGED";    // Names of temporary tables
  194.  
  195.     Screen("*** Table Copy Example ***\r\n");
  196.  
  197.     BREAK_IN_DEBUGGER();
  198.  
  199.     Screen("    Initializing IDAPI...");
  200.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  201.     {
  202.         Screen("\r\n*** End of Example ***");
  203.         return;
  204.     }
  205.  
  206.     Screen("    Setting the database directory...");
  207.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  208.     ChkRslt(rslt, "SetDirectory");
  209.  
  210.     Screen("    Create the %s dBASE table...", szDBTblName);
  211.     if (CreateDBTable(&hDb) != DBIERR_NONE)
  212.     {
  213.         CloseDbAndExit(&hDb);
  214.         Screen("\r\n*** End of Example ***");
  215.         return;
  216.     }
  217.  
  218.     Screen("    Open the %s table we just created...", szDBTblName);
  219.     rslt = DbiOpenTable(hDb, (pCHAR) szDBTblName, (pCHAR) szDBTblType,
  220.                         NULL, NULL, 0, dbiREADWRITE, dbiOPENSHARED,
  221.                         xltFIELD, FALSE, NULL, &hCurDB);
  222.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  223.     {
  224.         CloseDbAndExit(&hDb);
  225.         Screen("\r\n*** End of Example ***");
  226.         return;
  227.     }
  228.  
  229.     rslt = DbiSetToBegin(hCurDB);
  230.     ChkRslt(rslt, "SetToBegin");
  231.  
  232.     Screen("    Displaying the %s table...", szDBTblName);
  233.     DisplayTable(hCurDB, 0);
  234.  
  235.     Screen("\r\n    Create the %s PARADOX table...", szPXTblName);
  236.     if (CreatePXTable(&hDb) != DBIERR_NONE)
  237.     {
  238.         CloseDbAndExit(&hDb);
  239.         Screen("\r\n*** End of Example ***");
  240.         return;
  241.     }
  242.  
  243.     Screen("    Open the %s table which we just created...",
  244.            szPXTblName);
  245.     rslt = DbiOpenTable(hDb, (pCHAR) szPXTblName, (pCHAR) szPXTblType,
  246.                         NULL, NULL, 0, dbiREADWRITE, dbiOPENSHARED,
  247.                         xltFIELD, FALSE, NULL, &hCurPX);
  248.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  249.     {
  250.         CloseDbAndExit(&hDb);
  251.         Screen("\r\n*** End of Example ***");
  252.         return;
  253.     }
  254.  
  255.     rslt = DbiSetToBegin(hCurPX);
  256.     ChkRslt(rslt, "SetToBegin");
  257.  
  258.     Screen("    Displaying the %s table...", szPXTblName);
  259.     DisplayTable(hCurPX, 0);
  260.  
  261.     rslt = DbiSetToBegin(hCurPX);
  262.     ChkRslt(rslt, "SetToBegin");
  263.  
  264.     Screen("\r\n    Appending the %s table to the %s table...",
  265.            szPXTblName, szDBTblName);
  266.     rslt = DbiBatchMove(NULL, hCurPX, NULL, hCurDB, batAPPEND, 3,
  267.                         uaSrcRecs, 0, 0, 0, szKeyViol, szProblems,
  268.                         szChanged, &ulProbRecs, &ulKeyViolRecs,
  269.                         &ulChangedRecs, FALSE, FALSE, &ulNumRecs, TRUE);
  270.     ChkRslt(rslt, "Batch Move");
  271.  
  272.     rslt = DbiSetToBegin(hCurDB);
  273.     ChkRslt(rslt, "SetToBegin");
  274.  
  275.     Screen("    Displaying the updated %s table...", szDBTblName);
  276.     DisplayTable(hCurDB, 0);
  277.  
  278.     Screen("\r\n    Close the %s table...", szPXTblName);
  279.     rslt = DbiCloseCursor(&hCurPX);
  280.     ChkRslt(rslt, "CloseCur");
  281.  
  282.     Screen("    Delete the %s table...", szPXTblName);
  283.     rslt = DbiDeleteTable(hDb,(pCHAR) szPXTblName, (pCHAR) szPXTblType);
  284.     ChkRslt(rslt, "DeleteTable");
  285.  
  286.     Screen("    Close the %s table...", szDBTblName);
  287.     rslt = DbiCloseCursor(&hCurDB);
  288.     ChkRslt(rslt, "CloseCur");
  289.  
  290.     Screen("    Delete the %s table...", szDBTblName);
  291.     rslt = DbiDeleteTable(hDb,(pCHAR) szDBTblName, (pCHAR) szDBTblType);
  292.     ChkRslt(rslt, "DeleteTable");
  293.  
  294.     Screen("    Close the database and exit IDAPI...");
  295.     CloseDbAndExit(&hDb);
  296.  
  297.     Screen("\r\n*** End of Example ***");
  298. }
  299.  
  300. //=====================================================================
  301. //  Function:
  302. //          CreateDBTable(phDb);
  303. //
  304. //  Input:  phDb    - Pointer to the database handle
  305. //
  306. //  Return: Result of the table initialization
  307. //
  308. //  Description:
  309. //          This function creates a dBASE table and fills the table
  310. //          with a few records.  
  311. //=====================================================================
  312. DBIResult
  313. CreateDBTable (phDBIDb phDb)
  314. {
  315.     DBIResult   rslt;               // Value returned from IDAPI functions
  316.     hDBICur     hCur;               // Cursor handle for the table that is
  317.                                     //   created
  318.     CRTblDesc   crTblDsc;           // Table descriptor
  319.     BOOL        bOverWrite = TRUE;  // Overwrite, yes/no flag
  320.  
  321.     // The number of fields in the table - note that DBfldDesc is defined
  322.     // globally.
  323.     const unsigned uNumFields = sizeof(DBfldDesc) / sizeof (DBfldDesc[0]);
  324.  
  325.     // Number of indexes to be created when the table is created.
  326.     const unsigned uNumIndexes = sizeof(DBidxDesc) / sizeof(DBidxDesc[0]);
  327.  
  328.     // Initialize the table create descriptor.
  329.     memset(&crTblDsc, 0, sizeof(CRTblDesc));
  330.     strcpy(crTblDsc.szTblName, szDBTblName);
  331.     strcpy(crTblDsc.szTblType, szDBTblType);
  332.     crTblDsc.iFldCount     = uNumFields;
  333.     crTblDsc.pfldDesc      = DBfldDesc;
  334.     crTblDsc.iIdxCount     = uNumIndexes ;
  335.     crTblDsc.pidxDesc      = DBidxDesc ;
  336.  
  337.     // Create the table using information supplied in the table
  338.     //   descriptor above.
  339.     rslt = DbiCreateTable(*phDb, bOverWrite, &crTblDsc);
  340.     if (ChkRslt(rslt, "CreateTable") != DBIERR_NONE)
  341.     {
  342.         return rslt;
  343.     }
  344.  
  345.     // Open the table.
  346.     rslt = DbiOpenTable(*phDb, (pCHAR) szDBTblName, (pCHAR) szDBTblType,
  347.                         NULL, NULL, 0, dbiREADWRITE, dbiOPENSHARED,
  348.                         xltFIELD, FALSE, NULL, &hCur);
  349.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  350.     {
  351.         return rslt;
  352.     }
  353.  
  354.     // Add records to the table.
  355.     AddRecordDB(&hCur, "Jeffery", "San Jose", "1/28/1967");
  356.     AddRecordDB(&hCur, "William", "New York", "8/12/1970");
  357.     AddRecordDB(&hCur, "Jimmy", "San Francisco", "3/10/1924");
  358.     AddRecordDB(&hCur, "Larry", "Germany", "12/22/1933");
  359.  
  360.     rslt = DbiCloseCursor(&hCur);
  361.     ChkRslt(rslt, "CloseCursor");
  362.  
  363.     return rslt;
  364. }
  365.  
  366. //=====================================================================
  367. //  Function:
  368. //          CreatePXTable(phDb);
  369. //
  370. //  Input:  phDb    - Pointer to the database handle
  371. //
  372. //  Return: Result of the table initialization
  373. //
  374. //  Description:
  375. //          This function will create a Paradox table and fill the
  376. //          table with a few records.  
  377. //=====================================================================
  378. DBIResult
  379. CreatePXTable (phDBIDb phDb)
  380. {
  381.     DBIResult   rslt;              // Value returned from IDAPI functions
  382.     hDBICur     hCur;              // Cursor handle for the table that is
  383.                                    //   created
  384.     CRTblDesc   crTblDsc;          // Table descriptor
  385.     BOOL        bOverWrite = TRUE; // Overwrite, yes/no flag
  386.  
  387.     // The number of fields in the table.
  388.     const unsigned uNumFields = sizeof(PXfldDesc) / sizeof (PXfldDesc[0]);
  389.  
  390.     // Number of indexes to be created when the table is created.
  391.     const unsigned uNumIndexes = sizeof(PXidxDesc) / sizeof(PXidxDesc[0]);
  392.  
  393.     // Initialize the table create descriptor.
  394.     memset(&crTblDsc, 0, sizeof(CRTblDesc));
  395.     strcpy(crTblDsc.szTblName, szPXTblName);
  396.     strcpy(crTblDsc.szTblType, szPXTblType);
  397.     crTblDsc.iFldCount     = uNumFields;
  398.     crTblDsc.pfldDesc      = PXfldDesc;
  399.     crTblDsc.iIdxCount     = uNumIndexes;
  400.     crTblDsc.pidxDesc      = PXidxDesc;
  401.  
  402.     // Create the table using information supplied in the table
  403.     //   descriptor above.
  404.     rslt = DbiCreateTable(*phDb, bOverWrite, &crTblDsc);
  405.     if (ChkRslt(rslt, "CreateTable") != DBIERR_NONE)
  406.     {
  407.         return rslt;
  408.     }
  409.  
  410.     rslt = DbiOpenTable(*phDb, (pCHAR) szPXTblName, (pCHAR) szPXTblType,
  411.                         NULL, NULL, 0, dbiREADWRITE, dbiOPENSHARED,
  412.                         xltFIELD, FALSE, NULL, &hCur);
  413.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  414.     {
  415.         return rslt;
  416.     }
  417.  
  418.     AddRecord(&hCur, "David", "John", "Smith", 7, 28, 1968, "Chicago");
  419.     AddRecord(&hCur, "Tracy", "Joy", "Thomas", 12, 27, 1969, "Hermosa Beach");
  420.     AddRecord(&hCur, "John", "Boy", "Doe", 2, 7, 1954, "Ohmaha");
  421.     AddRecord(&hCur, "Klaus", "Epstein", "Stern", 4, 13, 1970, "Tel Aviv");
  422.  
  423.     rslt = DbiCloseCursor(&hCur);
  424.     ChkRslt(rslt, "CloseCursor");
  425.  
  426.     return rslt;
  427. }
  428.  
  429. //=====================================================================
  430. //  Function:
  431. //          AddRecordDB(hCur, pszName, pszPOB, pszDate);
  432. //
  433. //  Input:  hCur    - Cursor handle
  434. //          pszName - Value for the name field
  435. //          pszDate - Value for the date field
  436. //          pszPOB  - Value for the "Place of Birth" field
  437. //
  438. //  Return: Result of adding the record to the table
  439. //
  440. //  Description:
  441. //          This function will add a record to the given dBASE table.
  442. //=====================================================================
  443. DBIResult
  444. AddRecordDB (phDBICur hCur, pCHAR pszName, pCHAR pszPOB, pCHAR pszDate)
  445. {
  446.     DBIResult   rslt;       // Value returned from IDAPI functions
  447.     CURProps    TblProps;   // Table properties
  448.     pBYTE       pRecBuf;    // Record buffer
  449.  
  450.     //  Allocate a record buffer
  451.     rslt = DbiGetCursorProps(*hCur, &TblProps);
  452.     ChkRslt(rslt, "GetProps");
  453.  
  454.     pRecBuf = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
  455.     if (pRecBuf == NULL)
  456.     {
  457.         Screen("    Error - Out of memory");
  458.         return DBIERR_NOMEMORY;
  459.     }
  460.  
  461.     //  Clear, fill, and insert the record.
  462.     rslt = DbiInitRecord(*hCur, pRecBuf);
  463.     ChkRslt(rslt, "InitRecord");
  464.  
  465.     rslt = DbiPutField(*hCur, 1, pRecBuf, (pBYTE) pszName);
  466.     ChkRslt(rslt, "PutField");
  467.  
  468.     rslt = DbiPutField(*hCur, 2,  pRecBuf, (pBYTE) pszPOB);
  469.     ChkRslt(rslt, "PutField");
  470.  
  471.     rslt = DbiPutField(*hCur, 3,  pRecBuf, (pBYTE) pszDate);
  472.     ChkRslt(rslt, "PutField");
  473.  
  474.     rslt = DbiInsertRecord(*hCur, dbiNOLOCK, pRecBuf);
  475.     ChkRslt(rslt, "InsertRec");
  476.  
  477.     free(pRecBuf);
  478.  
  479.     return rslt;
  480. }
  481.  
  482. //=====================================================================
  483. //  Function:
  484. //          AddRecord(hCur, pszFirst, pszMiddle, pszLast, iMonth, iDay,
  485. //                    iYear, pszPOB);
  486. //
  487. //  Input:  hCur        - Pointer to the cursor handle
  488. //          pszFirst    - First name
  489. //          pszMiddle   - Middle name
  490. //          pszLast     - Last name
  491. //          iMonth      - Month of Birth
  492. //          iDay        - Day of Birth
  493. //          iYear       - Year of Birth
  494. //          pszPOB      - Place of birth
  495. //
  496. //  Return: Result of adding the record to the table
  497. //
  498. //  Description:
  499. //          This function will add a record to the given table.
  500. //=====================================================================
  501. DBIResult
  502. AddRecord (phDBICur hCur, pCHAR pszFirst, pCHAR pszMiddle, pCHAR pszLast,
  503.            UINT16 iMonth, UINT16 iDay, UINT16 iYear, pCHAR pszPOB)
  504. {
  505.     DBIDATE        Date;           // Date structure
  506.     DBIResult   rslt;           // Value returned from IDAPI functions
  507.     CURProps    TblProps;       // Table Properties
  508.     pBYTE       pRecBuf;        // Record Buffer
  509.  
  510.     //  Allocate a record buffer.
  511.     rslt = DbiGetCursorProps(*hCur, &TblProps);
  512.     ChkRslt(rslt, "GetCursorProps");
  513.  
  514.     pRecBuf = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
  515.     if (pRecBuf == NULL)
  516.     {
  517.         return DBIERR_NOMEMORY;
  518.     }
  519.  
  520.     //  Make sure we're starting with a clean record buffer.
  521.     rslt = DbiInitRecord(*hCur, pRecBuf);
  522.     ChkRslt(rslt, "InitRecord");
  523.  
  524.     // First Name.
  525.     rslt = DbiPutField(*hCur, 1, pRecBuf, (pBYTE) pszFirst);
  526.     ChkRslt(rslt, "PutField");
  527.  
  528.     // Middle Name.
  529.     rslt = DbiPutField(*hCur, 2, pRecBuf, (pBYTE) pszMiddle);
  530.     ChkRslt(rslt, "PutField");
  531.  
  532.     // Last Name.
  533.     rslt = DbiPutField(*hCur, 3, pRecBuf, (pBYTE) pszLast);
  534.     ChkRslt(rslt, "PutField");
  535.  
  536.     // Date of Birth.
  537.     rslt = DbiDateEncode(iMonth, iDay, iYear, &Date);
  538.     ChkRslt(rslt, "DateEncode");
  539.  
  540.     rslt = DbiPutField(*hCur, 4,  pRecBuf, (pBYTE) &Date);
  541.     ChkRslt(rslt, "PutField");
  542.  
  543.     // Place of Birth.
  544.     rslt = DbiPutField(*hCur, 5,  pRecBuf, (pBYTE) pszPOB);
  545.     ChkRslt(rslt, "PutField");
  546.  
  547.     rslt = DbiInsertRecord(*hCur, dbiNOLOCK, pRecBuf),
  548.     ChkRslt(rslt, "InsertRecord");
  549.  
  550.     free(pRecBuf);
  551.  
  552.     return rslt;
  553. }
  554.