本文整理汇总了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);
//}
}