from cursor
此函数通过游标获取位于指定位置的对象的引用。
MCO_RET classname_from_cursor(
/*IN*/ mco_trans_h trans,
/*IN*/ mco_cursor_h cursor
/*OUT*/ classname * handle
);
参数
trans
mco_trans_h
由 mco_trans_start()
函数返回的 MCO_READ_WRITE
事务句柄。
cursor
mco_cursor_h
一个通过树索引 _search
函数或其中一个游标导航函数定位到对象的 mco_cursor_h 实例。
handle
classname *
类句柄类型变量的地址。
返回
MCO_S_OK
成功引用对象。
MCO_E_CURSOR_INVALID
无效的指针。
MCO_ERR_CURSOR
游标特定错误。
示例
/* 应用程序代码片段 */
const char * db_name = "treedb";
int main(int argc, char* argv[])
{
MCO_RET rc = MCO_S_OK;
mco_db_h db = 0;
sample_memory_t dbmem;
mco_trans_h t;
mco_cursor_t csr;
int i;
Record rec;
uint4 key;
char name[64];
uint2 size;
int nRecs = 1001;
char str[64];
sample_os_initialize(DEFAULT);
sample_header( sample_descr );
/* Set fatal error handler and start SmartEDB runtime */
mco_error_set_handler( &sample_errhandler );
mco_runtime_start();
/* Open and connect to database */
rc = sample_open_database( db_name, treedb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE,
MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 5, &dbmem );
...
/* Fill database */
printf( "\n\tInsert 1000 test records " );
for ( i = 0; i < 1000 && MCO_S_OK == rc; i++ )
{
rc = mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t );
...
/* Get Record from cursor */
rc = Record_from_cursor( t, &csr, &rec );
...
}
}