Basic operations
All of these operations (except EnumerateEntries) can be invoked via RPC. They take a RPC.Conversation as the first argument so that secure remote procedure calls can be made to a LoganBerry database server; see LupineUsersGuide.tioga for information on establishing secure conversations.
Conv: TYPE = RPC.Conversation;
Errors raised during the execution of an operation indicate uncommon or abnormal conditions. Clients should be prepared to catch these.
Error: ERROR [ec: ErrorCode, explanation: ROPE ← NIL];
ErrorCode:
TYPE =
ATOM;
The possible ErrorCodes are:
$BadSchema, -- the schema can not be parsed
$CantOpenSchema, -- the schema file could not be opened
$BadDBHandle, -- an invalid OpenDB handle was passed to some routine
$BadCursor, -- an invalid cursor was passed to some routine
$NoIndex, -- the key presented in a read or delete operation has no associated index
$NoPrimaryKey, -- a new entry being written does not contain a primary key
$ValueNotUnique, -- a new entry being written contains the same primary key value as an existing entry, or the value supplied for a delete does not uniquely specifiy an entry
$CantOpenLog, -- a log file could not be opened
$BadLogEntry, -- a log entry is of the wrong format
$LogReadOnly, -- the specified log can not be updated
$InvalidReplace, -- an entry being replaced is in a different log than its replacement
$CantOpenIndex, -- a btree file could not be opened
$BadIndex, -- a btree index is corrupted
$DBClosed, -- the database has been closed
$DBNotAvailable, -- the database has been taken out of general service
$InternalError -- indicates some miscellaneous internal error
Open:
PROC [conv: Conv ←
NIL, dbName:
ROPE]
RETURNS [db: OpenDB];
Initiates database activity and checks for consistency. This can be called any number of times to get a new OpenDB handle or reopen a database that has been closed. Indices are automatically rebuilt if any are missing or if a partially-completed update left them out-of-date.
Errors: CantOpenSchema, BadSchema, CantOpenLog, BadIndex
Describe:
PROC [conv: Conv ←
NIL, db: OpenDB]
RETURNS [info: SchemaInfo];
Returns schema information about the database.
Errors: BadDBHandle
ReadEntry:
PROC [conv: Conv ←
NIL, db: OpenDB, key: AttributeType, value: AttributeValue]
RETURNS [entry: Entry, others:
BOOLEAN];
Returns an entry that contains the given attribute value for the given key; returns NIL if none exists. If the key refers to the primary index then the unique entry is returned and `others' is FALSE. If the key is secondary and several entries exist with the same value for the key, then an arbitrary entry is returned and `others' is set to TRUE; use EnumerateEntries to get all of the matching entries.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, BadLogEntry
EntryProc: TYPE = PROC [entry: Entry] RETURNS [continue: BOOL];
EnumerateEntries:
PROC [db: OpenDB, key: AttributeType, start: AttributeValue ←
NIL, end: AttributeValue ←
NIL, proc: EntryProc]
RETURNS [];
Calls `proc' for each entry in the specified range of key values. The enumeration is halted when either the range of entries is exhausted or `proc' returns FALSE. A NIL value for `start' represents the least attribute value, while a NIL value for `end' represents the largest attribute value. Thus, the complete database can be enumerated by specifying start=NIL and end=NIL with `key' equal to the primary key.
WARNING: THIS ROUTINE CAN NOT BE USED ACROSS AN RPC CONNECTION; USE GenerateEntries INSTEAD.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, BadLogEntry
GenerateEntries:
PROC [conv: Conv ←
NIL, db: OpenDB, key: AttributeType, start: AttributeValue ←
NIL, end: AttributeValue ←
NIL]
RETURNS [cursor: Cursor];
Similar to EnumerateEntries, but creates a cursor so that entries in the specified range of key values can be retrieved using NextEntry (defined below). Initially, the cursor points to the start of the sequence. A NIL value for `start' represents the least attribute value, while a NIL value for `end' represents the largest attribute value. Thus, the complete database can be enumerated by specifying start=NIL and end=NIL with `key' equal to the primary key.
Errors: BadDBHandle, NoIndex
NextEntry:
PROC [conv: Conv ←
NIL, cursor: Cursor, dir: CursorDirection ← increasing]
RETURNS [entry: Entry];
Retrieves the next entry relative to the given cursor. The cursor, and thus the sequence of desired entries, must have been previously created by a call to GenerateEntries. The cursor is automatically updated so that NextEntry may be repeatedly called to enumerate entries. NIL is returned if the cursor is at the end of the sequence and dir=increasing or at the start of the sequence and dir=decreasing.
Errors: BadCursor, DBClosed, BadIndex, BadLogEntry
EndGenerate:
PROC [conv: Conv ←
NIL, cursor: Cursor]
RETURNS [];
Releases the cursor; no further operations may be performed using the given cursor. This must be called once for every call to GenerateEntries.
WriteEntry:
PROC [conv: Conv ←
NIL, db: OpenDB, entry: Entry, log: LogID ← activityLog, replace:
BOOLEAN ←
FALSE]
RETURNS [];
Adds a new entry to the database. The entry is added to the activity log unless another log is explicitly requested. The entry must have an attribute for the primary key. The primary attribute value must be unique throughout the database unless replace=TRUE; in this case, an existing entry with the same primary attribute value is atomically replaced with the new entry (both must reside in the same log).
Errors: BadDBHandle, NoPrimaryKey, ValueNotUnique, LogReadOnly, InvalidReplace, DBClosed, BadIndex
DeleteEntry:
PROC [conv: Conv ←
NIL, db: OpenDB, key: AttributeType, value: AttributeValue]
RETURNS [];
Deletes the entry that contains the given attribute value for the given key. If the key is for a secondary index and the value is not unique then an Error[ValueNotUnique] is raised. Deletes are actually performed by logging the delete request (so that the log can be replayed at a later time) and then updating all of the indices.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, ValueNotUnique, LogReadOnly, BadLogEntry
Close:
PROC [conv: Conv ←
NIL, db: OpenDB]
RETURNS [];
Terminates database activity and closes all log and index files. Databases are always maintained consistently on disk so it doesn't hurt to leave a database open. The main reason for calling Close is to release the FS locks on the log files so they can be manually edited.
WARNING: THIS SHOULD NOT BE CALLED IF THE DATABASE IS BEING SHARED BY MULTIPLE CLIENTS.
Errors: BadDBHandle