mco_db_connect_ctx
接口适用于实时数据库 RT 。
连接到指定上下文的数据库。
此函数连接到数据库,指定连接上下文值,这些值稍后可用于特定于应用程序的目的。
MCO_RET mco_db_connect_ctx(
/*IN*/ const char * dbname,
/*IN*/ void const* context,
/*OUT*/ mco_db_h *db
);
参数
dbname
const char *
要连接到的数据库的名称。
context
void const*
数据库上下文数据的地址,或者调用 mco_db_connection_context()
函数,该函数返回与现有数据库连接相关联的上下文的地址。
db
mco_db_h
此数据库连接的数据库句柄的地址。
返回
MCO_S_OK
已成功创建数据库连接。
MCO_E_NOINSTANCE
指定的数据库未打开。
MCO_ERR_TRN
发生数据库事务错误。(例如。数据库已经被具有打开事务的其他线程打开.)
示例
/* 应用程序代码片段 */
const char * dbname = "SimpleDb";
int get_pid()
{
#ifdef _WIN32
return GetCurrentProcessId();
#else
return getpid();
#endif
}
int main(int argc, char* argv[])
{
mco_db_h db;
MCO_RET rc;
mco_device_t dev;
mco_db_params_t db_params;
int pid = get_pid();
...
rc = mco_db_open_dev( dbname, simpledb_get_dictionary(), &dev, 1, &db_params );
/* Allow duplicate instances because all processes connect to the same db */
if ( MCO_S_OK == rc || MCO_E_INSTANCE_DUPLICATE == rc ) {
/* connect using mco_db_connect_ctx() and pass &pid as parameter */
rc = mco_db_connect_ctx(dbname, &pid, &db);
if ( MCO_S_OK == rc )
{
...
}
}
...
}
文件
- 头文件:
mco.h
- 源文件:
mcoabst.c
- 库:
libmcolib.a