KI_INFO
Argument | Enumeration | Purpose |
---|---|---|
handle | Handle | |
path | Path number | |
SYM(buf$) | Symbol of a buffer to hold data | |
eOpt | KDB_INFO_OPTS_ENUM | Row count and serial number options |
status | KDB_ERROR_ENUM | Return status |
KI_INFO
This routine returns information about the table in a structure whose symbol index is passed in sym. The information returned depends on the value of the handle and path parameters passed in the call. The structure to be returned should be declared as a DEFRECORD using the appropriate built in constants and indexed using the built in fields defined therein.
Table information
If the variable path is zero in the call, then information about the table open on the handle is supplied. Getting the row count or the current autoserial value for Oracle tables can be slow, so the optional eOpts enumerated constant argument makes these operations optional.
To discover if the table is empty _KDB_INFO_TEST_FOR_ROWS tries to read a single row, returning the number of rows read, 0 or 1. For Oracle this is quicker than getting the exact row count. For compatibility with Oracle, KDB also honours this optional argument.
The options for are controlled by a KCML enumerated constants documented here. The row count options are an enumeration which can be added to the autoserial option.
For example:
DIM key_info$_KDB_INFO_HAND status = 'KI_INFO(handle, 0, SYM(key_info$), _KDB_INFO_ROW_COUNT)
For KDB type 7 and all SQL database tables key_info$ must be an instance of the KDB_INFO_HAND record.
For KDB type 6 and earlier tables the following subset of fields are available in a 224 byte string key_info$:
Offset | length | purpose |
---|---|---|
1 | 1 | 'K' for native KCML database table, 'Q' for a layered SQL database table, e.g. Oracle |
2 | 1 | version number (in ASCII) |
3 | 1 | LSB of partition no. of exclusive owner (in binary) |
4 | 1 | number of indices (in binary) |
5 | 2 | row length in bytes |
14 | 1 | MSB of partition no. of exclusive owner (in binary) |
22 | 2 | maximum index blocks (obsolete, see offset 85) |
24 | 2 | index blocks in use (obsolete, see offset 81) |
42 | 3 | maximum rows (obsolete, see offset 77) |
45 | 3 | count of rows in table (obsolete, see offset 73) |
54 | 3 | next available row number (obsolete, see offset 89) |
65 | 1 | KCML stream number (obsolete, KCML4 and earlier only, no longer supported) |
66 | 1 | Last major error code for the handle |
67 | 1 | Last minor error code for the handle |
68 | 1 | Last Operating System error code for the handle |
69 | 1 | Handle status as a bit field containing the following, 0x00 unused 0x01 nothing open now 0x02 open/connected 0x04 SQL prepared 0x08 result set exists 0x10 flat file open 0x20 BU file open |
73 | 4 | count of rows in table |
77 | 4 | max allowed rows in table |
81 | 4 | count of index blocks in use |
85 | 4 | max allowed index blocks |
89 | 4 | data high water mark |
93 | 1 | Mode that the table was opened with (KCML 6.00 or later), eg "R"ead, "W"rite etc. |
94 | 1 | number of index extents in a KISAM type 6 table |
95 | 1 | number of data extents in a KISAM type 6 table |
129 | 96 | table name |
Connection information
If the handle supplied is negative then information is returned about the connection open on that handle, e.g.
DIM key_info$_KDB_INFO_CONN status = 'KI_INFO(-hConnect, 0, SYM(key_info$))
Here key_info$ must be an instance of a KDB_INFO_CONN record.
Index information
In the example below, if path is non-zero, then information about index key path is returned in the variable ki_info$, e.g.:
DIM key_info$_KDB_INFO_IDX status = 'KI_INFO(handle, path, SYM(key_info$))
For KDB type 7 and all SQL databases key_info$ must be an instance of a KDB_INFO_IDX record. It contains an array of KDB_INFO_COL records detailing the columns within the key.
For KDB type 6 and earlier tables key_info$ should be a string of at least 72 bytes which will be returned in this format:
Offset | length | purpose |
---|---|---|
1 | 2 | reserved |
3 | 1 | total key length |
4 | 1 | duplicates allowed (Y/N) |
5 | 3 | reserved |
8 | 64 | index column descriptor array |
The type 6 key segment array must be at least 32 bytes long, 8 * 4 bytes. The key component structure is the same array specified in KI_CREATE. The first two bytes of each element define the byte offset of the start of that column. A zero start indicates the end of the components. The third byte defines the length of that component (total key length must not exceed 128). The fourth byte is currently reserved and must be zero.
Offset | length | purpose |
---|---|---|
1 | 2 | start of column, counted from 1 |
3 | 1 | length of column, binary |
4 | 1 | flag byte, HEX(00) for now |
Word search index information
If path is negative, and the open table is a KDB type 7 or SQL database table, then word search index information is returned in an instance of a KDB_INFO_WSX record.
The index column descriptor array holds information for the fields from which words are to be extracted and is an 8 element array, with each element an instance of the KDB_INFO_WS_COL record.