_DBReplace() Function Requires Record to Be Locked

Last reviewed: June 27, 1995
Article ID: Q117594
The information in this article applies to:
  • Microsoft FoxPro Library Construction Kit for MS-DOS, versions 2.0, 2.5, 2.6
  • Microsoft FoxPro Library Construction Kit for Windows, versions 2.5, 2.6

SUMMARY

When you are attempting to use the _DBReplace() function to place a new value in a field, _DBReplace() will return a negative integer if the current record is not locked.

_DBReplace() provides functionality similar to the FoxPro REPLACE command, but replaces the value of only one record at a time. When you attempt to use _DBReplace() to place a new value in a field, _DBReplace() will return a 0 if the replacement was successful or a negative integer whose absolute value is a FoxPro error number if the replacement was unsuccessful. Unlike the FoxPro REPLACE command, _DBReplace() must lock the current record in order to perform the replacement.

The sample code below illustrates how the _DBReplace() function works.

MORE INFORMATION

To run the sample code below, you will need to use the following syntax:

   USE <FoxPro_directory>\TUTORIAL\CUSTOMER
   =DBLOCK1(@<fieldname>,"<info_to_replace>",<work_area_number>)

When you are using _DBReplace(), you must pass the name of the field that contains the information you want to replace.

NOTE: To see the error, you must comment (remark) out the following line of code as shown (this line is used to lock the record):

   /*if(_DBLock((int)parm->p[2].val.ev_long,DBL_RECORD) <= 0)
   _Execute("Wait Window 'Could not lock record'");*/

Sample Code

   #include <pro_ext.h>

   void FAR dbfunc(ParamBlk FAR *parm)
   {
      int retval=0;
      _DBUnwind((int)parm->p[2].val.ev_long);
      _DBAppend((int)parm->p[2].val.ev_long,0);

      if(_DBLock((int)parm->p[2].val.ev_long,DBL_RECORD) <= 0)
         _Execute("Wait Window 'Could not lock record'");

         /*_Execute("=RLOCK()") can also be used*/

      retval=_DBReplace(&parm->p[0].loc,&parm->p[1].val);

      if(retval<=-1)
         _Error(retval);

      _DBUnlock((int)parm->p[2].val.ev_long);
      /*_Execute("UNLOCK") can also be used*/
   }

   FoxInfo myFoxInfo[] =
   {
   {"DBLOCK1", (FPFI) dbfunc, 3, "R,C,I"}
   };

   FoxTable _FoxTable =
   {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
   };


Additional reference words: FoxWin FoxDos 2.00 2.50 2.60 API LCK
KBCategory: kbinterop kbtool kbprg kbcode
KBSubcategory: FxtoolLck


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.