当前位置: 首页>>代码示例>>C++>>正文


C++ CDBManager::initDB方法代码示例

本文整理汇总了C++中CDBManager::initDB方法的典型用法代码示例。如果您正苦于以下问题:C++ CDBManager::initDB方法的具体用法?C++ CDBManager::initDB怎么用?C++ CDBManager::initDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDBManager的用法示例。


在下文中一共展示了CDBManager::initDB方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buffered_on_read

/**
* Called by libevent when there is data to read.
*/
void buffered_on_read(struct bufferevent *bev, void *arg) {
	client_t *client = (client_t *)arg;
	char data[BUF_MAX_SIZE] = { 0 };
	int nbytes;
	nbytes = EVBUFFER_LENGTH(bev->input);
	evbuffer_remove(bev->input, data, nbytes);
	//解析data
	string sdata = data;
	printf("recv sdata : %s\n", sdata.c_str());
	Json::Reader reader;
	Json::Value value, return_item;
	Json::FastWriter writer_item;
	if (reader.parse(sdata, value) && (!value["FunctionName"].isNull()))
	{
		CDBManager MyDB;
		MyDB.initDB("localhost", "root", "123456", "JiaTuanSql");
		string sFunctionName = value["FunctionName"].asString();
		if ("register" == sFunctionName)
		{
			if (MyDB.user_register_func(value["PhoneNO"].asString(), value["Pwd"].asString()))
			{
				return_item["error_code"] = 0;
			}
			else
			{
				return_item["error_code"] = -111;
				return_item["error_desc"] = "register failed,maybe user_login duplicate.";
			}
		}
		else if ("login" == sFunctionName)
		{
			if (MyDB.user_login_func(value["User_login"].asString(), value["User_pass"].asString()))
			{
				return_item["error_code"] = 0;
			}
			else
			{
				return_item["error_code"] = -121;
				return_item["error_desc"] = "login failed,maybe the account or password mistake.";
			}
		}
	}
	else
	{
		return_item["error_code"] = -11;
		return_item["error_desc"] = "Error:json data parse.";
	}
	sdata = writer_item.write(return_item);
	printf("send sdata : %s\n", sdata.c_str());
	evbuffer_add(client->output_buffer, sdata.c_str(), sdata.size());
	if (bufferevent_write_buffer(bev, client->output_buffer)) {
		errorOut("Error sending data to client on fd %d\n", client->fd);
		closeClient(client);
	}



	///* Copy the data from the input buffer to the output buffer in 4096-byte chunks.
	//* There is a one-liner to do the whole thing in one shot, but the purpose of this server
	//* is to show actual real-world reading and writing of the input and output buffers,
	//* so we won't take that shortcut here. */
	//while ((nbytes = EVBUFFER_LENGTH(bev->input)) > 0) {
	//	/* Remove a chunk of data from the input buffer, copying it into our local array (data). */
	//	if (nbytes > 4096) nbytes = 4096;
	//	evbuffer_remove(bev->input, data, nbytes);
	//	/* Add the chunk of data from our local array (data) to the client's output buffer. */
	//	evbuffer_add(client->output_buffer, data, nbytes);
	//}

	///* Send the results to the client.  This actually only queues the results for sending.
	//* Sending will occur asynchronously, handled by libevent. */
	//if (bufferevent_write_buffer(bev, client->output_buffer)) {
	//	errorOut("Error sending data to client on fd %d\n", client->fd);
	//	closeClient(client);
	//}
}
开发者ID:github188,项目名称:JiaTuanServer,代码行数:79,代码来源:server_threaded.c


注:本文中的CDBManager::initDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。