| Tutorial | Description |
|---|---|
| Athlete tutorial | This tutorial uses Data Explorer and API Explorer web apps to create an athlete table with indexes. It inserts records. It creates a transaction to update and delete records and rolls back the transaction. It retrieves records using cursors and SQL. |
| Count and paginate records | This tutorial shows how to perform a SQL query and use cursors to paginate results with a count of records read for each page. |
Set up the API Console
- Ensure the FairCom server is installed and running.
- Confirm server access by running FairCom's Control Center.
- Navigate to the Code tab.
- Select API Console from the Code menu.

Get records from a cursor
- Paste the following code into the API Console. Note that you must have a valid
"cursorId"by calling another"getRecords…"action with"returnCursor"set totruein the"params"property.{ "api": "db", "action": "getRecordsFromCursor", "params": { "cursorId": "replaceThisWithTheLastCreatedCursor", "fetchRecords": 1 }, "authToken": "replaceThisWithValidAuthToken" }
- Click the Run button.
- Continue to click the Run button to move through each record.
- The same code fetches different records each time it is run because each call moves the cursor position.
- To fetch records from different locations in the recordset, change the values of
"startFrom","skipRecords", and"fetchRecords".- The API Console automatically recognizes the
"cursorId"in a response and remembers it. So, when you select the"getRecordsFromCursor"action from the JSON Actions dropdown menu, the API Console automatically populates the action with the latest"cursorId"value to simplify using cursors.
- The API Console automatically recognizes the
Ways to move a cursor and retrieve records
The following lists contain techniques, examples, and capabilities of cursors.
"fetchRecords", "skipRecords", and "startFrom" to move the cursor:
- To fetch forwards, assign a positive integer number to
"fetchRecords". - To fetch backwards, assign a negative integer number to
"fetchRecords". - To skip forwards, assign a positive integer number to
"skipRecords". - To skip backwards, assign a negative integer number to
"skipRecords". - To move a cursor to the beginning of the recordset, set the
"startFrom"property to"beforeFirstRecord". - To move a cursor to the end of the recordset, set the
"startFrom"property to"afterLastRecord".
- To return the next two records:
"fetchRecords": 2 - To return the previous three records:
"fetchRecords": -3 - To skip the next two records and fetch 1 record:
"skipRecords": 2, "fetchRecords": 1 - To skip the previous record before the next 3 previous records:
"skipRecords": -1 , "fetchRecords": -3 - To fetch the first 3 records in the recordset:
"startFrom": "beforeFirstRecord", "fetchRecords": 3 - To fetch the last 3 records in the recordset:
"startFrom": "afterLastRecord", "skipRecords": -3, "fetchRecords": 3
-
"getRecordsFromTable"allows the cursor to move through every record in the table from beginning to end. -
"getRecordsUsingSQL"allows the cursor to move through every record returned by the SQL query from beginning to end.
-
"getRecordsByIndex"allows the cursor to move through every record in the index. -
"getRecordsStartingAtKey"allows the cursor to move through every record in the index starting with the closest match to the key. -
"getRecordsByPartialKeyRange"allows the cursor to move through every record in the index that matches the partial key. -
"getRecordsInKeyRange"allows the cursor to move through every record in the index within the specified key range.
Rebuild tables and indexes
Rebuilding tables and indexes takes a lot of time when the table being rebuilt has many records. There is no need to rebuild an index unless your index has experienced data corruption. For more guidance, contact FairCom support.
This tutorial rebuilds tables and indexes by running the "rebuildTables" and "rebuildIndexes" actions.
Rebuilding indexes and tables is only necessary if their data becomes corrupted. There are several common instances in which this can occur.
- Corruption is frequently encountered with non-transaction-controlled files. This happens to nearly all such files at some point. Because each application is responsible for its own data updates with no central point of control, if the application fails during an update, it can leave the index out of sync with the data file.
- Copying files that are under active server control can also cause data corruption, requiring a full rebuild of the tables.
- Another reason to rebuild is to save time and space when backing up files. If you obtain and archive a clean copy of the data files, their indexes can be rebuilt after the data is restored.
It is important to note that rebuilding can be a very time-consuming and memory-intensive process that can affect system performance. To help mitigate a dip in performance, you can use the SORT_MEMORY configuration option to allocate percentages or portions of available RAM toward rebuilding. This preserves system speed by rebuilding indexes without committing all available RAM, which would leave the system unusable or slow while rebuilding.
Rebuild indexes
Running the following request will rebuild the specified index.
- Navigate to the Code tab.
- Select API Console from the Data menu.
- Paste this code into the API Console editor:
{ "api": "db", "action": "rebuildIndexes", "params": { "tableName": "test1" }, "authToken": "replaceWithAuthTokenFromCreateSession", "requestId": "00000001" }
- Click the Run button.
Rebuild tables
Running the following request will rebuild the specified tables.
- Navigate to the Code tab.
- Select API Console from the Data menu.
- Paste this code into the API Console editor:
{ "api": "db", "action": "rebuildTables", "params": { "tableNames": [ "test1" ] }, "authToken": "replaceWithAuthTokenFromCreateSession", "requestId": "00000001" }
- Click the Run button.