xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

DELETE

Marks one or more records for deletion.

Syntax

DELETE [<Scope>]
[WHILE <lWhileCondition>]
  [FOR <lForCondition>]

Arguments

<Scope>
This option defines the number of records to mark for deletion. It defaults to the current record. The NEXT <nCount> scope deletes the next <nCount> records, while the RECORD <nRecno> scope deletes only one record having the record number <nRecno>. The option ALL marks all records for deletion.
WHILE <lWhileCondition>
This is a logical expression indicating to continue marking records for deletion while the condition is true. The DELETE command stops as soon as <lWhileCondition> yields .F. (false).
FOR <lForCondition>
This is a logical expression which is evaluated for all records in the current work area. Those records where <lForCondition> yields .T. (true) are marked for deletion.

Description

The DELETE command marks one or more records in the current work area for deletion. Records with the deletion flag set become unvisible when SET DELTED is set to ON. Whether or not the deleted flag is set for the current record can be tested with the Deleted() function. The flag marks a record only logically for deletion, it does not remove s record physically from a database file. The logical deletion flag can be removed with the RECALL command.

When a database is open in SHARED mode, the current record must be locked with the RLock() function before DELETE may be called. Failure to do so generates a runtime error. If multiple records should be marked for deletion, the entire file must be locked using FLock(), or the file must be open in EXCLUSIVE mode.

The PACK command removes all records with the deletion flag set physically from a database. The ZAP command removes all records at once, leaving an empty database file.

Note:  When the current record is marked for deletion and SET DELETED is ON, the record remains visible until the record pointer is moved.

Info

See also:DbDelete(), DbEval(), DbRecall(), Deleted(), FLock(), PACK, RECALL, RLock(), SET DELETED, ZAP
Category: Database commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the effect of SET DELETED with a record
// marked for deletion

   PROCEDURE Main
      USE Customer EXCLUSIVE

      GO TOP
      ? Deleted()                      // result; .F.
      ? Recno()                        // result: 1
      DELETE
      SET DELETED ON

      GO TOP
      ? Deleted()                      // result; .F.
      ? Recno()                        // result: 2

      SET DELETED OFF
      GO TOP
      ? Deleted()                      // result; .T.
      ? Recno()                        // result: 1

      RECALL
      ? Deleted()                      // result; .F.

      CLOSE Customer
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe