2.2 Accessing a table
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Managing external tables for SWI-Prolog
        • Managing external tables
          • Accessing a table
            • Finding record locations in a table
              • get_table_attribute/3
              • table_window/3
              • table_start_of_record/4
              • table_previous_record/3
            • Reading records
            • Searching the table
            • Miscellaneous

2.2.1 Finding record locations in a table

Records are addressed by their offset in the table (file). As records have generally non-fixed length, searching is often required. The predicates below allow for finding records in the file.

get_table_attribute(+Handle, +Attribute, -Value)
Fetch attributes of the table. Defined attributes:

fileUnify value with the name of the file with which the table is associated.
field(N)Unify value with declaration of n-th (1-based) field.
field_separatorUnify value with the field separator character.
record_separatorUnify value with the record separator character.
key_fieldUnify value with the 1-based index of the field that is sorted or fails if the table contains no sorted fields.
field_countUnify value with the total number of columns in the table.
sizeUnify value with the number of characters in the table-file, not the number of records.
windowUnify value with a term Start - Size, indicating the properties of the current window.
table_window(+Handle, +Start, +Size)
If only part of the file represents the table, this call may be used to define a window on the file. Start defines the start of the window relative to the start of the file. Size is the size in characters. Skipping a header is one of the possible purposes for this call.
table_start_of_record(+Handle, +From, +To, -Start)
Enumerates (on backtracking) the start of records in the table in the region [From, To). Together with read_table_record/4, this may be used to read the table's data.
table_previous_record(+Handle, +Here, -Previous)
If Here is the start of a record, find the start of the record before it. If Here points at an arbitrary location in a record, the start of this record will be returned.