|
The QMSetLeft() and QMSetRight() functions set the scanning position of an alternate key index at the extreme left or right of the data. They are analogous to the QMBasic SETLEFT and SETRIGHT statements.
The function arguments are:
| FileNo | is the file number returned by a previous QMOpen() call. |
| IndexName | is the name of the alternate key index to be used. |
The QMSetLeft and QMSetRight functions are used with QMSelectLeft() and QMSelectRight() to set the scan position to the first or last entry in an alternate key index.
The QMStatus() function returns zero if the operation is successful, non-zero if it fails because the index does not exist.
The example program fragments below use QMSetLeft() to set the scan position for an index on the CODE field to the leftmost item and walk through successive entries, processing each record.
void QMSetLeft(int FileNo, char * IndexName)
void QMSetRight(int FileNo, char * IndexName)
QMSetLeft(fData, "CODE");
while(1)
{
Key = QMSelectRight(fData, "CODE", 1);
if (QMStatus() != 0) break;
while((Id = QMReadNext(1)) != NULL)
{
if (Id == NULL) break;
Rec = QMRead(fData, Id, &Err);
if (Err == 0)
{
...process record...
QMFree(Rec);
}
QMFree(Id);
}
QMFree(Key);
}
The returned pointers from several functions in this example reference dynamically allocated memory areas that must be released using QMFree() when no longer needed.
|
QMSetLeft(ByVal FileNo as Integer, ByVal IndexName as String)
QMSetRight(ByVal FileNo as Integer, ByVal IndexName as String)
QMSetLeft(fData, "CODE")
Do
Key = QMSelectRight(fData, "CODE", 1)
If QMStatus() <> 0 Then Exit Do
Do
Id = QMReadNext(1)
If Id = Nothing Then Exit Do
Rec = QMRead(fData, Id, Err)
If Err = 0 Then
...process record...
End If
Loop
Loop
|
SetLeft(FileNo, IndexName
SetRight(FileNo, IndexName)
session->SetLeft(fData, "CODE")
loop
Key = session->SelectRight(fData, "CODE", 1)
until session->ServerStatus
loop
Id = session->ReadNext(1)
until Id = ""
Rec = session->Read(fData, Id, Err)
if Err = 0 then
...process record...
end
repeat
repeat
|
void SelectLeft(int FileNo, String IndexName)
void SelectRight(int FileNo, String IndexName)
qm.SetLeft(fData, "CODE");
while(true)
{
Key = qm.SelectRight(fData, "CODE", 1);
if (qm.ServerStatus != 0) break;
while(true)
{
Id = qm.ReadNext(1);
if (qm.ServerError != SV$OK) break;
Rec = qm.Read(fData, Id);
if (qm.ServerError == 0)
{
...process record...
}
}
}
|
SetLeft(FileNo, IndexName)
SetRight(FileNo, IndexName)
qm.SetLeft(fData, "CODE")
while True:
Key = qm.SelectRight(fData, "CODE", 1)
if qm.Status() != 0: break
while True:
Id = qm.ReadNext(1)
if Id = "": break
Rec, Err == qm.Read(fData, Id)
if Err == 0:
...process record...
|
|