|
ITTIA DB SQL C API
5.4.0
|
A table cursor provides direct access to a database table and, optionally, one of its indexes.
To obtain a cursor handle for a table, call
| #define DB_INSERT_SEEK_NEW _DB_INSERT_SEEK_NEW |
Move the cursor position to the inserted record.
| #define DB_UPDATE_SEEK_NEW _DB_UPDATE_SEEK_NEW |
Move the cursor position to the new position of the current record, if the record's position has changed after the update.
| #define DB_DELETE_SEEK_NEXT _DB_DELETE_SEEK_NEXT |
Move the cursor position to the next record.
| #define DB_SEEK_LESS _DB_SEEK_LESS |
Less than.
| #define DB_UPDATE_SEEK_NEXT _DB_UPDATE_SEEK_NEXT |
Move the cursor position to the next record, based on the position of the record before the update.
| #define DB_UPDATE_SEEK_PRIOR _DB_UPDATE_SEEK_PRIOR |
Move the cursor position to the previous record, based on the position of the record before the update.
| #define DB_DELETE_SEEK_PRIOR _DB_DELETE_SEEK_PRIOR |
Move the cursor position to the prior record.
| #define DB_SEEK_LESS_OR_EQUAL _DB_SEEK_LESS_OR_EQUAL |
Less than or equal to.
| #define DB_SEEK_FIRST_EQUAL _DB_SEEK_FIRST_EQUAL |
First exact match.
| #define DB_SEEK_LAST_EQUAL _DB_SEEK_LAST_EQUAL |
Last exact match.
| #define DB_SEEK_GREATER _DB_SEEK_GREATER |
Greater than.
| #define DB_SEEK_GREATER_OR_EQUAL _DB_SEEK_GREATER_OR_EQUAL |
Greater than or equal to.
| #define DB_SEEK_EQUAL _DB_SEEK_EQUAL |
Equivalent to DB_SEEK_FIRST_EQUAL.
| db_result_t db_table_cursor_init | ( | db_table_cursor_t * | tcdef | ) |
Initialize a table cursor.
| tcdef | Table cursor configuration. |
On failure, one of the following error codes is set:
| db_result_t db_table_cursor_destroy | ( | db_table_cursor_t * | tcdef | ) |
Destroy a table cursor.
| tcdef | Table cursor configuration. |
On failure, one of the following error codes is set:
| db_cursor_t db_open_table_cursor | ( | db_t | hdb, |
| const db_objname_t * | table, | ||
| const db_table_cursor_t * | params | ||
| ) |
Obtain a cursor to access the data in a table.
| hdb | Database handle. |
| table | Table name. A name must start with a letter and can be followed by one or more letters, numbers, or underscores. |
| params | Cursor parameter structure. Use NULL to create a table scan cursor (no index) with all capabilities enabled. |
On failure, one of the following error codes is set:
| db_result_t db_seek_prior | ( | db_cursor_t | hcursor | ) |
Move the cursor to the previous row in the table or result set.
| hcursor | Cursor handle. |
On failure, one of the following error codes is set:
Forward-only SQL cursors cannot use this function.
| db_result_t db_seek_last | ( | db_cursor_t | hcursor | ) |
Move the cursor to the last row in the table or result set.
| hcursor | Cursor handle. |
On failure, one of the following error codes is set:
Forward-only SQL cursors cannot use this function.
| db_result_t db_seek | ( | db_cursor_t | hcursor, |
| db_seek_t | seek, | ||
| db_row_t | hrow, | ||
| db_object_t | uobject, | ||
| db_fieldno_t | nfields | ||
| ) |
Search for a row matching the criteria given in the row hrow.
The cursor is positioned on the first table row that is in the relationship seek to the data in hrow.
| hcursor | Cursor handle. |
| seek | |
| hrow | Row of search values. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
| nfields | The first nfields fields in the cursor's index will be used to find a match. |
On failure, one of the following error codes is set:
| db_result_t db_insert | ( | db_cursor_t | hcursor, |
| db_row_t | hrow, | ||
| db_object_t | uobject, | ||
| db_flags_t | flags | ||
| ) |
Insert the data in hrow into the table represented by the cursor and position the cursor on the inserted row.
| hcursor | Cursor handle. |
| hrow | Row of values for insert. Unbound fields will be treated as null. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
| flags | Post positioning flag
|
On failure, one of the following error codes is set:
| db_result_t db_delete | ( | db_cursor_t | hcursor, |
| db_flags_t | flags | ||
| ) |
Delete the current row in a cursor.
| hcursor | Cursor handle. |
| flags | Post positioning flag
|
On failure, one of the following error codes is set:
| db_result_t db_update | ( | db_cursor_t | hcursor, |
| db_row_t | hrow, | ||
| db_object_t | uobject | ||
| ) |
Update the contents of a cursor's current row using the data in hrow.
| hcursor | Cursor handle. |
| hrow | Row of values for update. Only bound fields will be updated. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
On failure, one of the following error codes is set:
If the position of the cursor after update is not important,
| db_result_t db_update_flags | ( | db_cursor_t | hcursor, |
| db_row_t | hrow, | ||
| db_object_t | uobject, | ||
| db_flags_t | flags | ||
| ) |
Update the contents of a cursor's current row using the data in hrow.
| hcursor | Cursor handle. |
| hrow | Row of values for update. Only bound fields will be updated. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
| flags | Position of the cursor after update. If no flags are specified, the final cursor position is undefined and execution may be faster. |
On failure, one of the following error codes is set:
| db_result_t db_get_bookmark | ( | db_cursor_t | hcursor, |
| db_oid_t * | bookmark | ||
| ) |
Set a bookmark to the cursor's current row.
| hcursor | Cursor handle. |
| bookmark | Returned bookmark id. |
On failure, one of the following error codes is set:
| db_result_t db_goto_bookmark | ( | db_cursor_t | hcursor, |
| const db_oid_t * | bookmark | ||
| ) |
Set a cursor's current row from a bookmark.
| hcursor | Cursor handle. |
| bookmark | Bookmark to go to. |
On failure, one of the following error codes is set:
| db_result_t db_set_range | ( | db_cursor_t | hcursor, |
| db_row_t | low_row, | ||
| db_object_t | low_uobject, | ||
| db_fieldno_t | low_size, | ||
| db_row_t | high_row, | ||
| db_object_t | high_uobject, | ||
| db_fieldno_t | high_size | ||
| ) |
Restrict a cursor to only access rows within a given range.
| hcursor | Cursor handle. |
| low_row | Low row handle. |
| low_uobject | Low bound object data. |
| low_size | Low size. |
| high_row | High row handle. |
| high_uobject | High bound object data. |
| high_size | High size. |
On failure, one of the following error codes is set:
| db_result_t db_add_filter | ( | db_cursor_t | hcursor, |
| db_seek_t | relation, | ||
| db_row_t | filter_row, | ||
| db_object_t | filter_row_uobject, | ||
| const db_indexfield_t * | fields, | ||
| db_fieldno_t | nfields | ||
| ) |
Filter a table cursor by one or more fields.
After the filter is applied, the cursor will only access rows that satisfy the filter criteria.
| hcursor | Cursor handle. |
| relation | Relation between values in the table and assigned values. |
| filter_row | A row of fields table fields for comparison. |
| filter_row_uobject | Binding object data for the filter row. |
| fields | List of fields to use in comparison, or NULL. Order is important. |
| nfields | Number of fields in the list. |
On failure, one of the following error codes is set:
The cursor position is not changed by db_add_filter. Filters are applied when the cursor is next positioned, usually by db_seek_next.
The row can be safely modified or destroyed after the filter is added. Additional filters can be added to the cursor by calling db_add_filter again with another row or the same row with new values assigned to it.
If an index was selected when the cursor was created, that index will be used to optimize performance if it starts with any filter fields. Otherwise,
the table until a row that satisfies the filter is found.
If fields is used, fields are compared in the order they appear in the list. A field is only used in the comparison if all earlier fields are equal in both filter_row and the table row. For example, the comparison:
("a", "z") =< ("c", "b") is true.
The same comparison, but with the order of the fields reversed:
("z', "a") =< ("b", "c") is false.
If fields is NULL or nfields is zero, all fields in filter_row are used in the comparison. Additionally, each field is compared individually and all fields must satisfy the relation. For example, the comparison:
("a", "b", "z") =< ("c", "b", "a")
is evaluated as three separate filters when fields is NULL:
("a") =< ("c") and ("b") =< ("b") and ("z") <= ("a")
The result of this comparison is false because "z" =< "a" is false.
| db_result_t db_remove_filters | ( | db_cursor_t | hcursor | ) |
Remove all filters applied to a cursor.
| hcursor | Cursor handle. |
| db_result_t db_sort | ( | db_cursor_t | hcursor, |
| const db_indexfield_t * | fields, | ||
| db_fieldno_t | nfields | ||
| ) |
Sort a table cursor dynamically.
| hcursor | Cursor handle. |
| fields | A list of fields by which to sort the cursor. |
| nfields | Number of fields in the list. |
If an index was selected when the cursor was created and that index can be used to fully sort the table, db_sort does nothing. Otherwise, the table is dynamically sorted. For best performance, apply filters to the table before sorting.
If db_add_filter, db_remove_filters, or db_set_range are called after a table has been sorted, they will not be active until until the next time
Set fields to NULL to remove the sort criteria, which will also apply any new filters.
| int db_is_sorted_by | ( | db_cursor_t | hcursor, |
| const db_indexfield_t * | fields, | ||
| db_fieldno_t | nfields | ||
| ) |
Determine whether a table cursor is sorted by a list of fields.
| fields | A list of fields. |
| nfields | Number of fields in the list. |
| hcursor | Cursor handle. |
The cursor's index and filters are used to determine whether the cursor is sorted by fields. If the cursor does not use an index, db_is_sorted_by will always return false.
This function can be used to predict whether or not db_sort will return immediately if called. If db_is_sorted_by returns true, db_sort would have no effect. If db_is_sorted_by returns false, db_sort would perform a dynamic sort.
| db_result_t db_qseek | ( | db_cursor_t | hcursor, |
| db_seek_t | seek, | ||
| const db_bind_t * | binds, | ||
| db_len_t | nbinds, | ||
| db_object_t | uobject, | ||
| db_fieldno_t | nfields | ||
| ) |
Position on the row matching the search criteria given the first nfields fields in the cursor's index.
| hcursor | Cursor handle. |
| seek | |
| binds | Relative field bindings. |
| nbinds | Number of fields bound. |
| uobject | Source for row contents. |
| nfields | Number of uobject criteria fields. |
On failure, one of the following error codes is set:
| db_result_t db_qinsert | ( | db_cursor_t | hcursor, |
| const db_bind_t * | binds, | ||
| db_len_t | nbinds, | ||
| db_object_t | uobject, | ||
| db_flags_t | flags | ||
| ) |
Insert a new row into a cursor's table using a binding array.
loop and db_insert inside the loop.
| hcursor | Cursor handle. |
| binds | Array of bindings. |
| nbinds | Number of fields in binds. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
| flags |
|
On failure, one of the following error codes is set:
| db_result_t db_qupdate | ( | db_cursor_t | hcursor, |
| const db_bind_t * | binds, | ||
| db_len_t | nbinds, | ||
| db_object_t | uobject | ||
| ) |
Update the contents of the cursor's current row using a binding array.
loop and db_update inside the loop.
| hcursor | Cursor handle. |
| binds | Array of bindings. |
| nbinds | Number of fields in binds. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
On failure, one of the following error codes is set:
If the position of the cursor after update is not important,
| db_result_t db_qupdate_flags | ( | db_cursor_t | hcursor, |
| const db_bind_t * | binds, | ||
| db_len_t | nbinds, | ||
| db_object_t | uobject, | ||
| db_flags_t | flags | ||
| ) |
Update the contents of the cursor's current row using a binding array.
loop and db_update inside the loop.
| hcursor | Cursor handle. |
| binds | Array of bindings. |
| nbinds | Number of fields in binds. |
| uobject | Row data for relative bindings. Use NULL if hrow does not contain relative bindings. |
| flags | Position of the cursor after update. If no flags are specified, the final cursor position is undefined and execution may be faster. |
On failure, one of the following error codes is set:
| db_result_t db_get_row_num | ( | db_cursor_t | hcursor, |
| int64_t * | num | ||
| ) |
Get the current row number from a numbered index.
If the cursor supports this feature, the row number will increase as the cursor seeks forward. The row number may increase by more than one for each row.
The number returned does not uniquely identify the row and may change if any row in the table is modified.
This function only supports a table cursor that was created using a numbered index.