- 论坛徽章:
- 0
|
本帖最后由 xpston008 于 2016-11-13 20:38 编辑
c驱动 mongo-c-driver-1.4.2(功能:一个线程查询数据后更新一个状态为处理状态
一个线程将处理结果后一些状态更新到这个表
数据量很大,所以分开两个线程。
)- BOOL RSmppMongoDb::_db_res_query()
- {
- const bson_t *doc;
- bson_error_t error;
-
- const char *collection_name = "cac_sms_sent_pool";
- bson_t *query;
- char *str;
- mongoc_collection_t *collection;
- mongoc_cursor_t *cursor;
-
-
- query = bson_new ();
- BSON_APPEND_UTF8 (query, "apply_state", "0");
- collection = mongoc_client_get_collection (m_pClient, "cac", collection_name);
- cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, \
- query, NULL,/* Fields, NULL for all. */ NULL); /* Read Prefs, NULL for default */
- while (mongoc_cursor_next (cursor, &doc))
- {
- str = bson_as_json (doc, NULL);
- fprintf (stdout, "%s\n", str);
- bson_free (str);
- }
-
- if (mongoc_cursor_error (cursor, &error)) {
- fprintf (stderr, "Cursor Failure: %s\n", error.message);
- return EXIT_FAILURE;
- }
-
- bson_destroy (query);
- mongoc_cursor_destroy (cursor);
- mongoc_collection_destroy (collection);
- }
复制代码 1. 这里面有哪些是非线程安全的函数。 是不是所有的操作都需要加锁,保证线程安全。2. 如此复杂的语句在c 里面该如何写 ,下面是mysql的语句。
- "UPDATE tb_test set apply_time=str_to_date('%s','%s') , \
- apply_state=CASE WHEN apply_state='-1' THEN '-1' ELSE '%d' END , \
- fail_apply_reason=concat(IFNULL(fail_apply_reason,''),'%s') , \
- return_message_id =concat(IFNULL(return_message_id,''),'%s ') \
- WHERE message_id='%s' ",iter->apply_time,"%Y%m%d%H%i%s", \
- iter->last_appy_state,iter->fail_reason,iter->return_message_id,iter->rec_id.c_str());
复制代码
大神们帮忙回复。
|
|