MCO_RET mco_uda_lookup( /*IN*/ mco_trans_h t,
/*IN*/ unsigned short struct_no,
/*IN*/ unsigned short index_no,
/*IN*/ MCO_OPCODE op,
/*IN*/ const mco_uda_value_t * keys,
/*IN*/ unsigned short keys_count,
/*OUT*/ mco_cursor_t * cursor );
| |
---|
t | 事务处理 |
struct_no | 结构/类编号(必须介于 0 和 - 1 之间)mco_dict_struct_count() |
index_no | 索引号(必须介于 0 和 - 1 之间)struct_info.index_count |
OP | 操作码(MCO_LT、MCO_LE、MCO_EQ、MCO_GE、MCO_GT)请注意,哈希索引只允许 MCO_EQ |
钥匙 | 搜索键数组 |
keys_count | 搜索键数组的长度。请注意,键的数量、它们的顺序和类型必须与索引的 DDL 描述相对应 |
光标 | 光标手柄 |
执行数据库查找。该函数将光标定位在满足搜索条件的第一个对象上。然后,可以使用 API 接收对象句柄。mco_uda_from_cursor()
| |
---|
MCO_S_OK | 找到对象 |
MCO_E_UDA_STRUCT_NOTFOUND | 无效struct_no |
MCO_E_UDA_STRUCT_NOT_CLASS | 无效 (不是类)struct_no |
MCO_E_UDA_INDEX_NOTFOUND | 无效index_no |
MCO_E_UDA_WRONG_KEY_NUM | 索引中定义的键数与实际数目不匹配keys_count |
MCO_E_UDA_WRONG_KEY_TYPE | 密钥类型不匹配 |
MCO_E_UDA_WRONG_OPCODE | 操作码无效(必须是 MCO_LT、MCO_LE、MCO_EQ、MCO_GE 或 MCO_GT;并且仅对哈希索引MCO_EQ) |
/* 应用程序代码片段 */
int main(int argc, char* argv[])
{
MCO_RET rc;
mco_db_h db;
mco_trans_h t;
mco_cursor_t csr;
mco_uda_value_t keys[1];
unsigned short struct_no = 1;
unsigned short index_no = 2;
mco_uda_object_handle_t uda_obj;
...
rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
if ( MCO_S_OK == rc)
{
...
keys[0].type = MCO_DD_UINT4;
keys[0].u4 = 120;
/* Lookup the first object with id >= 120. */
rc = mco_uda_lookup(t, Record_struct_no, index_no, MCO_GE,
keys, 1, &csr);
if ( MCO_S_OK == rc)
{
mco_uda_from_cursor(t, &csr, &uda_obj); /* get the handle */
...
}
}
...
}