HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ClipperVariablesStringsConditions (IF / DO CASE)Loops (FOR / DO WHILE)DBF Database
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
🔁 Condition & Loop
🗃️ Functions & Database
Clipper›DBF Database

DBF Database

Opening a DBF file, navigating between records, and reading field values.

Simple enough for a 5-year-old to understand

Open and read the table

Clipper's strongest feature is its ability to work directly with DBF tables. Use USE to open a table.

Example code
1
USE customers
Opens the customers.dbf file.
DatabaseOpens the customers.dbf file.
2
QOut(customers->name)
Prints the name field of the current record.
Output / InputPrints the name field of the current record.
3
CLOSE
Closes the table.
DatabaseCloses the table.
DatabaseOutput / Input
💡 Hint: When accessing a field name, the table name and arrow operator are used.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Which command opens a DBF table?

About this topic

Clipper's data model is file-based: each table is a data file, and each index is a separate file. There is no server process; the program opens and reads the files directly. This simplicity provided a major speed boost on the hardware of that era.

Access is handled via a record cursor. In an open table, there is always a "current record"; reading fields means reading this record. Advancing the cursor, positioning by searching for a condition, and testing for the end-of-file are the fundamental operations.

In multi-user access, the responsibility for locking belongs to the programmer. You must lock a record before updating it and release it when done. Code that skips locking works fine for a single user, but leads to data corruption on a network.

What you will learn

  • Opening tables and work areas
  • Record cursor operations
  • Using indexes and searching
  • Adding and updating records
  • Locking and deletion behavior

Who is this for?

  • Those working with xBase data files
  • Those maintaining multi-user installations
  • Those debugging legacy accounting programs

When to use?

When working with multiple tables, each table should be opened in a separate work area and fields should be accessed using aliases; code that relies on the active area will read the wrong table due to an intervening call.

In applications running on a network, every update must be performed by acquiring a lock, and the lock must be released as soon as the locking operation is finished.

Common mistakes

Wrong

PROCEDURE Main()
   USE musteri SHARED
   GO TOP
   REPLACE musteri->bakiye WITH 100
   RETURN

An attempt is made to update a record in a shared table without locking it; while another user writes to the same record, changes are lost or a runtime error occurs. A record lock must be acquired before updating and released when the operation is finished.

Correct

PROCEDURE Main()
   USE musteri SHARED
   GO TOP
   IF RLock()
      REPLACE musteri->bakiye WITH 100
      DbUnlock()
   ELSE
      ? "Record could not be locked"
   ENDIF
   RETURN

Wrong

PROCEDURE Main()
   USE musteri
   SET INDEX TO musteri_ad
   SEEK "Ahmet"
   ? musteri->bakiye
   RETURN

Because the search result is not checked, when a record is not found, the cursor remains at the end of the file and reading fields returns empty values; in some cases, data from an unrelated record is read. The found indicator must be tested after every search.

Correct

PROCEDURE Main()
   USE musteri
   SET INDEX TO musteri_ad
   SEEK "Ahmet"
   IF Found()
      ? musteri->bakiye
   ELSE
      ? "Record not found"
   ENDIF
   RETURN

Wrong

PROCEDURE Main()
   USE musteri
   GO TOP
   DELETE
   ? RecCount()
   RETURN

The delete command only marks the record as deleted; it does not remove it from the file, and the record count does not change. Depending on settings, marked records may continue to appear in reads. Physical deletion requires a pack command, which requires the table to be open exclusively.

Correct

PROCEDURE Main()
   USE musteri EXCLUSIVE
   GO TOP
   DELETE
   PACK
   ? RecCount()
   RETURN

Frequently asked questions

What is a work area?

Each open table is kept in a numbered work area, and a cursor movement in one does not affect the others. Accessing fields by alias makes it explicit in the code which table you are reading from and protects you from active area changes.

What does an index do?

It allows browsing records in a specific order and positioning directly at a value. Without an index, a search scans the entire file. If index files are not kept up to date along with the data file, they become corrupted and need to be rebuilt.

When should the lock be released?

As soon as the operation is finished. Holding a lock while the user waits on the screen blocks others in multi-user systems. The correct pattern is to read the data, edit it on the screen, then acquire the lock, write quickly, and release it.

Summary

Each table is a file, and each index is a separate file.

Access is handled via a record cursor.

After a search, the found indicator is tested.

A lock must be acquired before updating.

Deletion marks records, physical deletion requires packing.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code