This is an example of record retrieve both by percentage and fraction written in C++.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
static char *btrieveFileName = (char *)"squaresAndSquareRoots.btr";
#define MIN_X 0
#define MAX_X 255
#define NUMBER_OF_RECORDS (MAX_X - MIN_X + 1)
#pragma pack(1)
typedef struct {
uint8_t x;
uint16_t xSquared;
double xSquareRoot;
} record_t;
#pragma pack()
{
{
goto leave;
}
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
int i;
record_t record;
for (i = MIN_X; i <= MAX_X; i++)
{
record.x = (uint8_t)i;
record.xSquared = (uint16_t)(i * i);
record.xSquareRoot = sqrt((double)i);
{
goto leave;
}
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
leave:
return status;
}
{
long long cursorPosition;
int numerator;
int percentage;
record_t record;
uint8_t key;
{
goto leave;
}
printf("First: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByPercentage: 0%% record: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByFraction: %d/%d record: (%u, %u, %f)\n", 0, NUMBER_OF_RECORDS, record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByPercentage: 50%% record: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByFraction: %d/%d record: (%u, %u, %f)\n", NUMBER_OF_RECORDS / 2, NUMBER_OF_RECORDS, record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
{
goto leave;
}
printf("Last: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByPercentage: 100.00%% record: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByFraction: %d/%d record: (%u, %u, %f)\n", NUMBER_OF_RECORDS, NUMBER_OF_RECORDS, record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
printf("ByCursorPosition: record: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
key = (MAX_X - MIN_X) / 2;
{
goto leave;
}
printf("GetPercentage using Index: %d%% key: %d\n", percentage / 100, key);
if ((percentage = btrieveFile->
GetPercentage(cursorPosition)) == -1)
{
goto leave;
}
printf("GetPercentage using Cursor Position: %d%%\n", percentage / 100);
{
goto leave;
}
printf("GetNumerator using Index: %d/%d key: %d\n", numerator, NUMBER_OF_RECORDS, key);
if ((numerator = btrieveFile->
GetNumerator(cursorPosition, NUMBER_OF_RECORDS)) == -1)
{
goto leave;
}
printf("GetNumerator using Cursor Position: %d/%d\n", numerator, NUMBER_OF_RECORDS);
leave:
return status;
}
int
main(int argc, char *argv[])
{
static const char *usage = "Usage: %s\n";
if (argc != 1)
{
printf(usage, argv[0]);
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
leave:
return 0;
return 1;
}
The Btrieve client class.
Definition btrieveCpp.h:1388
Btrieve::StatusCode FileCreate(BtrieveFileAttributes *btrieveFileAttributes, const char *fileName, Btrieve::CreateMode createMode, Btrieve::LocationMode locationMode=Btrieve::LOCATION_MODE_NO_PREFERENCE)
Create a file.
Btrieve::StatusCode FileClose(BtrieveFile *btrieveFile)
Close a file.
Btrieve::StatusCode FileDelete(const char *fileName)
Delete a file.
Btrieve::StatusCode FileOpen(BtrieveFile *btrieveFile, const char *fileName, const char *ownerName, Btrieve::OpenMode openMode, Btrieve::LocationMode locationMode=Btrieve::LOCATION_MODE_NO_PREFERENCE)
Open a file.
The Btrieve file attributes class.
Definition btrieveCpp.h:2448
Btrieve::StatusCode SetFixedRecordLength(int fixedRecordLength)
Set the fixed record length.
The Btrieve file class.
Definition btrieveCpp.h:1729
int GetPercentage(long long cursorPosition)
Get the percentage which best approximates the location of the cursor position within the file.
int RecordRetrieveByFraction(Btrieve::Index index, int numerator, int denominator, char *record, int recordSize, Btrieve::LockMode lockMode=Btrieve::LOCK_MODE_NONE)
Retrieve a record by fraction.
int GetNumerator(long long cursorPosition, int denominator)
Get the numerator which best approximates the location of the cursor position within the file relativ...
Btrieve::StatusCode RecordCreate(char *record, int recordLength)
Create a record.
Btrieve::StatusCode IndexCreate(BtrieveIndexAttributes *btrieveIndexAttributes)
Create an index.
int RecordRetrieveFirst(Btrieve::Index index, char *record, int recordSize, Btrieve::LockMode lockMode=Btrieve::LOCK_MODE_NONE)
Retrieve the first record.
int RecordRetrieveLast(Btrieve::Index index, char *record, int recordSize, Btrieve::LockMode lockMode=Btrieve::LOCK_MODE_NONE)
Retrieve the last record.
Btrieve::StatusCode GetLastStatusCode()
Get the last status code.
int RecordRetrieveByCursorPosition(Btrieve::Index index, long long cursorPosition, char *record, int recordSize, Btrieve::LockMode lockMode=Btrieve::LOCK_MODE_NONE)
Retrieve a record by cursor position.
long long GetCursorPosition()
Get the cursor position.
int RecordRetrieveByPercentage(Btrieve::Index index, int percentage, char *record, int recordSize, Btrieve::LockMode lockMode=Btrieve::LOCK_MODE_NONE)
Retrieve a record by percentage.
The Btrieve index attributes class.
Definition btrieveCpp.h:3716
Btrieve::StatusCode AddKeySegment(BtrieveKeySegment *btrieveKeySegment)
Add a key segment.
The Btrieve key segment class.
Definition btrieveCpp.h:3874
Btrieve::StatusCode SetField(int offset, int length, Btrieve::DataType dataType)
Set the field.
static const char * StatusCodeToString(StatusCode statusCode)
Return a status code as a string.
@ CREATE_MODE_OVERWRITE
Overwrite.
Definition btrieveCpp.h:72
StatusCode
The Btrieve status codes.
Definition btrieveCpp.h:713
@ STATUS_CODE_UNKNOWN
-7 - Unknown.
Definition btrieveCpp.h:1194
@ STATUS_CODE_NO_ERROR
0 - No error.
Definition btrieveCpp.h:715
@ OPEN_MODE_NORMAL
Normal.
Definition btrieveCpp.h:606
@ DATA_TYPE_UNSIGNED_BINARY
Unsigned binary.
Definition btrieveCpp.h:205
@ INDEX_1
Index 1.
Definition btrieveCpp.h:311