static int drop_expire_tables(void) { if (settings.data_keep_time == 0) return 0; int i; for (i = 0; i < settings.hash_table_num; ++i) { char *table_name = get_table_name(i, -settings.data_keep_time); if (table_name == NULL) return -__LINE__; NEG_RET(drop_table(table_name)); } if (settings.hash_table_num > 1 && strcasecmp(settings.db_engine, "myisam") == 0) { char *merge_table = get_table_name(-1, -settings.data_keep_time); if (merge_table == NULL) return -__LINE__; NEG_RET(drop_table(merge_table)); } return 0; }
int pea_mail::mail_head_list(Cmessage * c_in, Cmessage * c_out) { db_proto_mail_head_list_in * p_in = P_IN; db_proto_mail_head_list_out * p_out = P_OUT; uint32_t user_id = p_in->db_user_id.user_id; uint32_t role_tm = p_in->db_user_id.role_tm; uint32_t server_id = p_in->db_user_id.server_id; GEN_SQLSTR(sqlstr, "select mail_id, mail_time, mail_state, mail_templet, mail_type, sender_id, sender_role_tm, sender_nick, mail_title from %s where receive_id = %u and receive_role_tm = %u and server_id = %u order by mail_time desc limit %u", get_table_name(user_id), user_id, role_tm, server_id, MAX_MAIL_COUNT ); STD_QUERY_WHILE_BEGIN_NEW(sqlstr, p_out->head_infos); INT_CPY_NEXT_FIELD(item.mail_id); INT_CPY_NEXT_FIELD(item.mail_time); INT_CPY_NEXT_FIELD(item.mail_state); INT_CPY_NEXT_FIELD(item.mail_templet); INT_CPY_NEXT_FIELD(item.mail_type); INT_CPY_NEXT_FIELD(item.sender_id); INT_CPY_NEXT_FIELD(item.sender_role_tm); BIN_CPY_NEXT_FIELD(item.sender_nick, sizeof(item.sender_nick)); BIN_CPY_NEXT_FIELD(item.mail_title, sizeof(item.mail_title)); STD_QUERY_WHILE_END_NEW(); }
Status HbaseDriver::create_index(const string &root, const string &name, int index_type, int key_type) { string table_name = get_table_name(root, name); string row_key = root + ":" + name; vector<Mutation> mutations; mutations.emplace_back(); mutations.back().column = "meta:table_name"; mutations.back().value = table_name; mutations.emplace_back(); mutations.back().column = "meta:index_name"; mutations.back().value = name; mutations.emplace_back(); mutations.back().column = "meta:index_type"; mutations.back().value = lexical_cast<string>(index_type); mutations.emplace_back(); mutations.back().column = "meta:key_type"; mutations.back().value = lexical_cast<string>(key_type); VLOG(2) << "Table name: " << table_name; map<string, string> attributes; hbase_->handler()->mutateRow(kTableName, row_key, mutations, attributes); VLOG(2) << "Create index table: " << table_name; vector<ColumnDescriptor> columns; columns.emplace_back(); columns.back().name = "file_id"; hbase_->handler()->createTable(table_name, columns); return Status::OK; }
/** * @brief update_db_nativertu * 常规设备更新 * @Param: rtuinfo * @Param: mode 模式 0 控制 1 编辑 常规设备信息 2 绑定负载 * 控制 : 传入 RelayInfo 数组中 val * 绑定负载: 传入 bind_num , RelayInfo 数组中 id,type,name[] ,path[] * 编辑 : 传入 RelayInfo [0] 中 id, name[] ,path[] * 设备头信息 RtuRegInfo 中的hostadd,rtuadd 必须传入 * Returns: 0 更新成功 -1 更新失败 */ int update_db_nativertu(NativeRtuInfo & rtuinfo, Uint8 mode) { ostringstream ostr; string setstr; string wherestr; string tablename=get_table_name(rtuinfo.rtuinfo.rtutype); Uint16 relayval; Uint64 UniqueIndex; UniqueIndex = rtuinfo.rtuinfo.hostadd; UniqueIndex = UniqueIndex << 32; UniqueIndex += rtuinfo.rtuinfo.rtuadd; ostr.str(""); ostr << "UniqueIndex=" << UniqueIndex; wherestr = ostr.str(); if(mode == 0) { /* 处理控制等帧 */ for (Int16 i = 0; i < 4;i++) { relayval = rtuinfo.relayinfo[i].val; printf("%d\n", relayval); if (!setstr.empty()) { setstr.append(","); } ostr.str(""); ostr << "Relay" << i + 1 << "Val=" << relayval; setstr += ostr.str(); } } else if(mode ==2) { /* 绑定负载 */ Uint16 relayid = 0; LOG_DEBUG("bind_num:%d\n",rtuinfo.bind_num); for (Int16 i = 0; i < rtuinfo.bind_num; i++) { relayid = rtuinfo.relayinfo[i].id; if (!setstr.empty()) setstr.append(","); ostr.str(""); ostr << "Relay" << relayid + 1 << "Type=" << rtuinfo.relayinfo[i].type << ",Relay" << relayid + 1 << "Name='" << rtuinfo.relayinfo[i].name << "',Relay" << relayid + 1 << "Path='" << rtuinfo.relayinfo[i].path << "'"; setstr += ostr.str(); } } else if(mode ==1 ) { Uint16 relayid = 0; ostr.str(""); relayid = rtuinfo.relayinfo[0].id; ostr << "Relay" << relayid + 1 << "Name='" << rtuinfo.relayinfo[0].name << "',Relay" << relayid + 1 << "Path='" << rtuinfo.relayinfo[0].path << "'"; setstr += ostr.str(); } return db_update_query(setstr,wherestr,tablename); }
int pea_mail::set_mail_read(db_user_id_t* db_user, uint32_t mail_id) { GEN_SQLSTR(sqlstr, "update %s set mail_state = 1 where mail_id = %u", get_table_name(db_user->user_id), mail_id ); return exec_update_sql(sqlstr, DB_ERR_NOT_EXIST); }
int pea_mail::clear_mail_enclosure(db_user_id_t* db_user, uint32_t mail_id) { GEN_SQLSTR(sqlstr, "update %s set numerical_enclosure = '', item_enclosure = '', equip_enclosure = '' where mail_id = %u", get_table_name(db_user->user_id), mail_id ); return exec_update_sql(sqlstr, DB_ERR_NOT_EXIST); }
int Cgf_achievement::clear_role_achievement(userid_t userid, uint32_t role_regtime) { GEN_SQLSTR(sqlstr, "delete from %s where userid=%u and role_regtime=%u", get_table_name(userid), userid, role_regtime); return exec_update_sql(sqlstr, SUCC); }
int Cgf_other_info::get_other_info_list(userid_t userid, uint32_t role_regtime, gf_get_other_info_list_out_item** pData, uint32_t* count) { GEN_SQLSTR(sqlstr, "select type, value from %s where userid = %u and role_regtime = %u order by type", get_table_name(userid), userid, role_regtime); STD_QUERY_WHILE_BEGIN(sqlstr, pData, count); INT_CPY_NEXT_FIELD( (*pData+i)->type); INT_CPY_NEXT_FIELD( (*pData+i)->value); STD_QUERY_WHILE_END(); }
int Cgf_achievement::get_achievement_data_list( userid_t userid, uint32_t role_regtime, gf_get_achievement_data_list_out_element** pdata, uint32_t *count) { GEN_SQLSTR(sqlstr, "select achieve_type, get_time from %s where userid = %u and role_regtime = %u", get_table_name(userid), userid, role_regtime); STD_QUERY_WHILE_BEGIN(sqlstr, pdata, count); INT_CPY_NEXT_FIELD( (*pdata+i)->achieve_type); INT_CPY_NEXT_FIELD( (*pdata+i)->get_time); STD_QUERY_WHILE_END(); }
void Room::prepare_params() { sqlite3_stmt *stmp; std::string sql_raw; if (id) sql_raw = "UPDATE `" + get_table_name() + "`\ SET `title`=? SET `description`=? SET `hotel_id`=? SET `position`=? SET `price`=? \ FROM id=?;"; else
void Country::prepare_params() { sqlite3_stmt *stmp; std::string sql_raw; if (id) sql_raw = "UPDATE `" + get_table_name() + "`\ SET `title`=? \ FROM id=?;"; else
wa::storage::cloud_table get_table(bool create) { wa::storage::cloud_table_client client = get_table_client(); utility::string_t table_name = get_table_name(); wa::storage::cloud_table table = client.get_table_reference(table_name); if (create) { table.create_if_not_exists(); } return table; }
int Cgf_achievement::replace_achievement_data(userid_t userid, uint32_t role_regtime, uint32_t type, uint32_t get_time) { GEN_SQLSTR(sqlstr, "replace into %s values(%u, %u, %u, %u)", get_table_name(userid), userid, role_regtime, type, get_time ); return exec_update_sql(sqlstr, SUCC); }
int Cgf_other_info::replace_other_info(userid_t userid, uint32_t role_regtime, uint32_t type, uint32_t value) { time_t now = time (NULL); GEN_SQLSTR(sqlstr, "replace into %s (userid, role_regtime, type, value, tm) values(%u, %u, %u, %u, %u)", get_table_name(userid), userid, role_regtime, type, value, (uint32_t)now); return exec_update_sql(sqlstr, SUCC); }
int pea_mail::get_total_mail_count(uint32_t userid, uint32_t role_tm, uint32_t server_id, uint32_t* count) { *count = 0; GEN_SQLSTR(sqlstr, "select count(*) from %s where receive_id = %u and receive_role_tm = %u and server_id = %u limit 1", get_table_name(userid), userid, role_tm, server_id ); STD_QUERY_ONE_BEGIN(sqlstr, DB_ERR_NOERROR) INT_CPY_NEXT_FIELD(*count); STD_QUERY_ONE_END(); }
int Cgf_summon_dragon_list::get_summon_dragon_list(uint32_t top_limit, gf_get_summon_dragon_list_out_item** pdata, uint32_t* count) { GEN_SQLSTR(sqlstr, "select userid,nick,nimbus,tm from %s order by tm desc limit %u", get_table_name(), top_limit); STD_QUERY_WHILE_BEGIN(this->sqlstr, pdata, count); INT_CPY_NEXT_FIELD( (*pdata+i)->uid ); BIN_CPY_NEXT_FIELD( (*pdata+i)->nick, NICK_LEN); INT_CPY_NEXT_FIELD( (*pdata+i)->nimbus ); INT_CPY_NEXT_FIELD( (*pdata+i)->tm ); STD_QUERY_WHILE_END(); }
int pea_mail::del_mail(Cmessage * c_in, Cmessage * c_out) { db_proto_del_mail_in* p_in = P_IN; db_proto_del_mail_out* p_out = P_OUT; uint32_t user_id = p_in->db_user_id.user_id; GEN_SQLSTR(sqlstr, "delete from %s where mail_id = %u", get_table_name(user_id), p_in->mail_id ); p_out->mail_id = p_in->mail_id; return exec_update_sql(sqlstr, DB_ERR_NOT_EXIST); }
int pea_mail::send_mail(db_user_id_t* db_user, uint8_t* sender_nick, uint32_t recevie_id, uint32_t recevie_role_tm, uint8_t* title, uint8_t* content, uint32_t time, uint32_t* mail_id) { GEN_SQLSTR(sqlstr, "insert into %s set mail_time = %u, mail_state = 2, mail_type = 2, server_id = %u, sender_id = %u, sender_role_tm = %u, sender_nick = '%s', receive_id = %u, receive_role_tm = %u, mail_title = '%s', mail_content = '%s'", get_table_name(recevie_id), time, db_user->server_id, db_user->user_id, db_user->role_tm, sender_nick, recevie_id, recevie_role_tm, title, content ); return exec_insert_sql_get_auto_increment_id(sqlstr, DB_ERR_NOERROR, mail_id); }
/** * @brief update_db_rtuinfo * 用户设备信息编辑 * @Param: hostinfo 该结构体所有字段必须传入 * 更新 设备名称和路径 * Returns: */ int update_db_rtuinfo(RtuUpdate & hostinfo) { ostringstream ostr; string setstr; string wherestr; Uint8 opertype=hostinfo.opertype; ostr.str(""); string tablename= get_table_name(hostinfo.rtutype); if (opertype == 0xff && hostinfo.rtutype == RTU_TYPE_SCENEINFO) { ostr << "SceneName='" << hostinfo.rtuname << "'"; setstr += ostr.str(); } else if (opertype == 0xff && hostinfo.rtutype == RTU_TYPE_TASKINFO) { ostr << "TaskName='" << hostinfo.rtuname << "'"; setstr += ostr.str(); } else if (opertype == 0xff) { ostr << "RtuName='" << hostinfo.rtuname << "',RtuPath='" << hostinfo.rtupath << "'"; setstr += ostr.str(); } else if (opertype < 3 && IsNativeRtu(hostinfo.rtutype)) { ostr << "Relay" << opertype + 1 << "Name='" << hostinfo.rtuname << "',Relay" << opertype + 1 << "Path='" << hostinfo.rtupath << "'"; setstr += ostr.str(); } else if (opertype < 16 && (hostinfo.rtutype == RTU_TYPE_BED)) { ostr << "Relay" << opertype + 1 << "Name='" << hostinfo.rtuname << "',Relay" << opertype + 1 << "Path='" << hostinfo.rtupath << "'"; setstr += ostr.str(); } Uint64 UniqueIndex = hostinfo.hostadd; UniqueIndex = UniqueIndex << 32; UniqueIndex += hostinfo.rtuadd; ostr.str(""); ostr << "UniqueIndex=" << UniqueIndex; wherestr = ostr.str(); return db_update_query(setstr,wherestr,tablename); }
TEST_FIXTURE(table_service_test_base, storage_extended_error_verify_json_with_details) { utility::string_t table_name = get_table_name(); azure::storage::cloud_table_client client = get_table_client(); azure::storage::cloud_table table = client.get_table_reference(table_name); azure::storage::table_request_options options; azure::storage::operation_context context; try { table.delete_table(options, context); CHECK(false); } catch (const azure::storage::storage_exception& e) { CHECK(e.result().extended_error().code().compare(U("ResourceNotFound")) == 0); CHECK(!e.result().extended_error().message().empty()); } }
static int create_new_tables(void) { int i; for (i = 0; i < settings.hash_table_num; ++i) { char *table_name = get_table_name(i, 0); if (table_name == NULL) return -__LINE__; char *create_sql = create_table_sql(table_name); if (create_sql == NULL) return -__LINE__; log_info("worker: %d, sql: %s", settings.worker_id, create_sql); int ret = db_query(create_sql, 0); if (ret < 0) { log_error("exec sql fail: %s, sql: %s", db_error(), create_sql); return -__LINE__; } } if (settings.hash_table_num > 1 && strcasecmp(settings.db_engine, "myisam") == 0) { char *merge_sql = create_merge_table_sql(0); if (merge_sql == NULL) return -__LINE__; log_debug("worker: %d, sql: %s", settings.worker_id, merge_sql); int ret = db_query(merge_sql, 0); if (ret < 0) { log_error("exec sql fail: %s, sql: %s", db_error(), merge_sql); return -__LINE__; } } return 0; }
/** * @brief update_db_scenertu * 更新情景面板 * @Param: rtuinfo * @Param: mode 模式: 1 编辑 2 修改绑定 * 编辑: 设备名称,设备路径 修改绑定: bind_num , 每个button的信息 ,包括id ,type,add,oper * Returns: */ int update_db_scenertu(SceneRtu & rtuinfo, Uint8 mode) { ostringstream ostr; string setstr; string wherestr; string tablename=get_table_name(rtuinfo.rtuinfo.rtutype); Uint64 UniqueIndex; UniqueIndex = rtuinfo.rtuinfo.hostadd; UniqueIndex = UniqueIndex << 32; UniqueIndex += rtuinfo.rtuinfo.rtuadd; ostr.str(""); ostr << "UniqueIndex=" << UniqueIndex; wherestr = ostr.str(); if(mode == 0) { LOG_ERROR("invalid mode...\n"); return -1; } else if(mode ==2) { /* 绑定修改 */ Uint16 buttonid = 0; for (Int16 i = 0; i < rtuinfo.bind_num; i++) { buttonid = rtuinfo.scene_bind[i].id; if (!setstr.empty()) setstr.append(","); ostr.str(""); ostr << "Button" << buttonid << "Type=" << rtuinfo.scene_bind[i].type << ",Button" << buttonid << "Add=" << rtuinfo.scene_bind[i].add << ",Button" << buttonid << "Oper=" << rtuinfo.scene_bind[i].oper; setstr += ostr.str(); } } else if(mode ==1 ) // 编辑 { ostr.str(""); ostr << "RtuName='" << rtuinfo.rtuinfo.rtuname << "',RtuPath='"<<rtuinfo.rtuinfo.rtupath<< "'"; setstr += ostr.str(); } return db_update_query(setstr,wherestr,tablename); }
/** * @brief update_db_exnativertu * 更新智能床 * @Param: rtuinfo * @Param: mode 0 控制 1 编辑 * 控制 : relayinfo 数组 中val值传入 床头位置(1) 床尾位置(1) 床头振动(1) 床尾振动(1) 灯状态(1):0x00表示关灯,0x01表示开灯 * 编辑 relayinfo[0] 中 name ,path 传入 * Returns: */ int update_db_exnativertu(ExNativeRtu & rtuinfo, Uint8 mode) { ostringstream ostr; string setstr; string wherestr; string tablename=get_table_name(RTU_TYPE_BED); Uint64 UniqueIndex; UniqueIndex = rtuinfo.rtuinfo.hostadd; UniqueIndex = UniqueIndex << 32; UniqueIndex += rtuinfo.rtuinfo.rtuadd; ostr.str(""); ostr << "UniqueIndex=" << UniqueIndex; wherestr = ostr.str(); Uint16 relayval = 0; if(mode == 0) { for (Int16 i = 0; i < 5; i++) { relayval = rtuinfo.relayinfo[i].val; if (!setstr.empty()) setstr.append(","); ostr.str(""); ostr << "Relay" << i + 1 << "Val=" << relayval; setstr += ostr.str(); } } else if(mode == 1) // 编辑 { ostr.str(""); ostr << "Relay1Name='" << rtuinfo.relayinfo[0].name << "',Relay1Path='" << rtuinfo.relayinfo[0].path << "'"; setstr = ostr.str(); } return db_update_query(setstr,wherestr,tablename); }
/** * @brief update_db_host * 更新主机信息表 * @Param: hostinfo * 更新信息: 传入 hostname ,hostip * Returns: */ int update_db_host(HostRegInfo & hostinfo) { ostringstream ostr; string setstr; string wherestr; ostr.str(""); ostr << "HostName='" << hostinfo.hostname << "'"; wherestr = ostr.str(); string tablename=get_table_name(RTU_TYPE_HOST); int count=findHostname(hostinfo.hostname); if(count < 0) { LOG_ERROR("findHostname error..\n"); return -1; } else if(count == 0) { LOG_ERROR("hostname no found..\n"); return -1; } else if(count > 0) { /* 更新主机 */ char lastcomtime[30]; get_sys_time(lastcomtime); ostr.str(""); ostr << "HostIP=" << hostinfo.hostip << ",LastComTime='" <<lastcomtime<< "'"; setstr = ostr.str(); } return db_update_query(setstr,wherestr,tablename); }
static bool maybe_create_table(conflate_handle_t *handle, sqlite3 *db, int flag, int flags, const char* query) { assert(db); assert(query); bool rv = true; char* table_name = get_table_name(flag); if (flag & flags) { CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Table %s already exists", table_name); } else { if (db_do(handle, db, query)) { CONFLATE_LOG(handle, LOG_LVL_INFO, "Created table: %s", table_name); } else { CONFLATE_LOG(handle, LOG_LVL_WARN, "DB error creating table: %s", table_name); rv = false; } } return rv; }
/** * @brief update_db_safetyrtu * 更新安防设备 * @Param: rtuinfo * @Param: mode : 0 控制 1 编辑 * 控制: 传入 布防状态 , 动作状态 编辑:传入 设备名称 ,设备路径 * hostadd ,rtuadd 必须 传入 * Returns: */ int update_db_safetyrtu(SafetyRtu & rtuinfo, Uint8 mode) { ostringstream ostr; string setstr; string wherestr; string tablename=get_table_name(rtuinfo.rtuinfo.rtutype); Uint64 UniqueIndex; UniqueIndex = rtuinfo.rtuinfo.hostadd; UniqueIndex = UniqueIndex << 32; UniqueIndex += rtuinfo.rtuinfo.rtuadd; ostr.str(""); ostr << "UniqueIndex=" << UniqueIndex; wherestr = ostr.str(); if (mode == 0) { ostr.str(""); ostr << "RtuActState=" << rtuinfo.rtuactstate << ",RtuPlace=" <<rtuinfo.rtuplace ; setstr = ostr.str(); } else if(mode == 1 ) { ostr.str(""); ostr << "RtuName='" << rtuinfo.rtuinfo.rtuname << "',RtuPath='"<<rtuinfo.rtuinfo.rtupath<< "'"; setstr += ostr.str(); } else { LOG_ERROR("type error.\n"); return -1; } return db_update_query(setstr,wherestr,tablename); }
/** * @brief insert_db_rtu * 注册设备接口 ,将设备写入数据库 * @Param: pRtuinfo 插入设备结构体 * * Returns:-1 插入失败 0 插入成功 */ int insert_db_rtu(RtuRegInfo* pRtuinfo) { if(pRtuinfo == NULL) { LOG_ERROR("pRtuinfo is NULL\n"); return -1; } RtuRegInfo rtuinfo = *pRtuinfo; // 拿到注册设备信息 int type =rtuinfo.rtutype; /* 拿到 表 名 */ string tablename=get_table_name(type); if(strcmp(tablename.c_str(),"") == 0 ) { LOG_ERROR("no such table.\n"); return -1; } string colstr="UniqueIndex,HostAdd,RtuAdd,RtuType,RtuRegTime,RtuState"; string valstr; ostringstream ostr; //include <sstream> ostr.str(""); ostr << rtuinfo.uniqueindex << "," << rtuinfo.hostadd << "," << rtuinfo.rtuadd << "," << type << "," <<"'" <<rtuinfo.rturegtime <<"'" <<"," <<rtuinfo.rtustate ; valstr = ostr.str(); if(db_insert_query(colstr,valstr,tablename)!=0) { LOG_ERROR("db_insert_query error...\n"); return -1; } ostr.str(""); ostr << "UniqueIndex,HostAdd,RtuAdd"; colstr = ostr.str(); ostr.str(""); ostr << rtuinfo.uniqueindex << "," << rtuinfo.hostadd << "," << rtuinfo.rtuadd; valstr = ostr.str(); /* 如果是安防设备 ,则插入另外的表 */ if(strcmp(tablename.c_str(),DB_TABLE_NAMELIST[6]) == 0 ) { tablename=DB_TABLE_NAMELIST[7]; if(db_insert_query(colstr,valstr,tablename)!=0) { return -1; } tablename=DB_TABLE_NAMELIST[8]; if(db_insert_query(colstr,valstr,tablename)!=0) { return -1; } tablename=DB_TABLE_NAMELIST[9]; if(db_insert_query(colstr,valstr,tablename)!=0) { return -1; } } /* 如果是传感器设备 ,则插入另外的表 */ else if (strcmp(tablename.c_str(),DB_TABLE_NAMELIST[11]) == 0 ) { tablename=DB_TABLE_NAMELIST[12]; if(db_insert_query(colstr,valstr,tablename)!=0) { return -1; } } return 0; }
int mysql_select(eng_ctx_t* eng_ctx) { int ret = 0; MYSQL* wmysql; MYSQL* rmysql; MYSQL_RES* wmysql_result; MYSQL_RES* rmysql_result; MYSQL_ROW wrow; MYSQL_ROW rrow; int wnum_fields; int rnum_fields; int wnum_rows; int rnum_rows; size_t* wlengths; size_t* rlengths; wmysql = get_server_mysql(eng_ctx->write_server); ret = mysql_select_db(wmysql, database); if (ret != 0) { return ret; } sql_gen(eng_ctx, SELECT); my_assert(eng_ctx->sql); const char* sql = eng_ctx->sql; // get pre data value from write server ret = mysql_real_query(wmysql, sql, strlen(sql)); if (ret != 0) { log_debug("%s", mysql_error(wmysql)); return ret; } eng_ctx->stats.nselect++; g_stat.nselect = __sync_add_and_fetch(&g_stat.nselect, 1); wmysql_result = mysql_store_result(wmysql); wnum_fields = mysql_num_fields(wmysql_result); wnum_rows = mysql_num_rows(wmysql_result); wrow = mysql_fetch_row(wmysql_result); wlengths = mysql_fetch_lengths(wmysql_result); if (0 == wnum_rows) { mysql_free_result(wmysql_result); return 1; // this obj do not exist in mysql } // get data from other nodes for (int i = 0; i < eng_ctx->nread_server; i++) { rmysql = get_server_mysql(eng_ctx->read_servers[i]); ret = mysql_select_db(rmysql, database); if (ret != 0) { log_warn("can not connect to server:%s, db:%s", get_server_name(eng_ctx->read_servers[i]), database); continue; } ret = mysql_real_query(rmysql, sql, strlen(sql)); if (ret != 0) { log_debug("%s", mysql_error(rmysql)); continue; } set_sql_read_time(eng_ctx); eng_ctx->stats.nselect++; g_stat.nselect = __sync_add_and_fetch(&g_stat.nselect, 1); rmysql_result = mysql_store_result(rmysql); rnum_fields = mysql_num_fields(rmysql_result); rnum_rows = mysql_num_rows(rmysql_result); rrow = mysql_fetch_row(rmysql_result); rlengths = mysql_fetch_lengths(rmysql_result); if (rnum_rows > 0) { for (int j = 0; j < wnum_fields; j++) { if (strncmp(wrow[j], rrow[j], wlengths[j]) != 0) { #ifdef READABLE_DATA_LOG char* logbuf_offset = eng_ctx->data_inconsist_log_buf; logbuf_offset += sprintf(logbuf_offset, "Check ERROR !!!\n"); logbuf_offset += sprintf(logbuf_offset, "Command: %s ", cmdtype_toString(eng_ctx->prev_cmd)); logbuf_offset += sprintf(logbuf_offset, "Host: %15s ", get_server_name(eng_ctx->write_server)); logbuf_offset += sprintf(logbuf_offset, "Table: %s ", get_table_name(eng_ctx->table)); logbuf_offset += sprintf(logbuf_offset, "Key: %.*s ", 20, wrow[0]); logbuf_offset += sprintf(logbuf_offset, "Value: %.*s ...\n", 8, wrow[1]); logbuf_offset += sprintf(logbuf_offset, "Command: SELECT "); logbuf_offset += sprintf(logbuf_offset, "Host: %15s ", get_server_name(eng_ctx->read_servers[i])); logbuf_offset += sprintf(logbuf_offset, "Table: %s ", get_table_name(eng_ctx->table)); logbuf_offset += sprintf(logbuf_offset, "Key: %.*s ", 20, rrow[0]); logbuf_offset += sprintf(logbuf_offset, "Value: %.*s ...\n\n", 8, rrow[1]); *(logbuf_offset) = '\0'; fprintf(stderr, "%s", eng_ctx->data_inconsist_log_buf); #else /* log_error("Data inconsistent detected!"); log_error("Write server is %s, read server is %s", get_server_name(eng_ctx->write_server), get_server_name(eng_ctx->read_servers[i])); log_error("Last command is %s", cmdtype_toString(eng_ctx->prev_cmd)); log_error("There are %lld microseconds since last successful" "sql request", diff_sql_write_read_time(eng_ctx)); abort(); */ #endif g_stat.ncheck_fail = __sync_add_and_fetch(&g_stat.ncheck_fail, 1); abort(); } } } else { #ifdef READABLE_DATA_LOG char* logbuf_offset = eng_ctx->data_inconsist_log_buf; logbuf_offset += sprintf(logbuf_offset, "Check ERROR !!!\n"); logbuf_offset += sprintf(logbuf_offset, "Command: %s ", cmdtype_toString(eng_ctx->prev_cmd)); logbuf_offset += sprintf(logbuf_offset, "Host: %15s ", get_server_name(eng_ctx->write_server)); logbuf_offset += sprintf(logbuf_offset, "Table: %s ", get_table_name(eng_ctx->table)); logbuf_offset += sprintf(logbuf_offset, "Key: %.*s ", 20, wrow[0]); logbuf_offset += sprintf(logbuf_offset, "Value: %.*s ...\n", 8, wrow[1]); logbuf_offset += sprintf(logbuf_offset, "Command: SELECT "); logbuf_offset += sprintf(logbuf_offset, "Host: %15s ", get_server_name(eng_ctx->read_servers[i])); logbuf_offset += sprintf(logbuf_offset, "Table: %s ", get_table_name(eng_ctx->table)); logbuf_offset += sprintf(logbuf_offset, "Key: NULL "); logbuf_offset += sprintf(logbuf_offset, "Value: NULL \n\n"); *(logbuf_offset) = '\0'; fprintf(stderr, "%s", eng_ctx->data_inconsist_log_buf); #else /* log_error("Data inconsistent detected!"); log_error("Write server is %s, read server is %s", get_server_name(eng_ctx->write_server), get_server_name(eng_ctx->read_servers[i])); log_error("Last command is %s", cmdtype_toString(eng_ctx->prev_cmd)); log_error("There are %lld microseconds since last successful" "sql request", diff_sql_write_read_time(eng_ctx)); abort(); */ #endif g_stat.ncheck_fail = __sync_add_and_fetch(&g_stat.ncheck_fail, 1); abort(); } mysql_free_result(rmysql_result); } mysql_free_result(wmysql_result); return 0; }
int pea_mail::query_mail_body(Cmessage * c_in, Cmessage * c_out) { db_proto_mail_body_in* p_in = P_IN; db_proto_mail_body_out* p_out = P_OUT; uint32_t user_id = p_in->db_user_id.user_id; GEN_SQLSTR(sqlstr, "select mail_id, mail_content, numerical_enclosure, item_enclosure, equip_enclosure from %s where mail_id = %u limit 1", get_table_name(user_id), p_in->mail_id); STD_QUERY_ONE_BEGIN(sqlstr, DB_ERR_NOT_EXIST); INT_CPY_NEXT_FIELD(p_out->mail_id); BIN_CPY_NEXT_FIELD(p_out->mail_content, sizeof(p_out->mail_content)); BIN_CPY_NEXT_FIELD(p_out->numerical_enclosure, sizeof(p_out->numerical_enclosure)); BIN_CPY_NEXT_FIELD(p_out->item_enclosure, sizeof(p_out->item_enclosure)); BIN_CPY_NEXT_FIELD(p_out->equip_enclosure, sizeof(p_out->equip_enclosure)); STD_QUERY_ONE_END(); }
int Cgf_pvp_game::get_final_score_rank_list(gf_get_pvp_game_rank_out_item** pData, uint32_t* count ,uint32_t rank) { if (rank == 1) { GEN_SQLSTR(sqlstr,"select userid, role_regtime, nick, lv, score from %s where pvp_type=2 and lv<51 and score <> 0 order by score desc limit 100", get_table_name()); } else if (rank == 2) { GEN_SQLSTR(sqlstr,"select userid, role_regtime, nick, lv, score from %s where pvp_type=2 and lv>50 and score <> 0 order by score desc limit 100", get_table_name()); } else { GEN_SQLSTR(sqlstr,"select userid, role_regtime, nick, lv, score from %s where pvp_type=2 and score <> 0 order by score desc limit 100", get_table_name()); } STD_QUERY_WHILE_BEGIN(this->sqlstr, pData, count); INT_CPY_NEXT_FIELD( (*pData+i)->userid); INT_CPY_NEXT_FIELD( (*pData+i)->roletm); BIN_CPY_NEXT_FIELD( (*pData+i)->nick, 16); INT_CPY_NEXT_FIELD( (*pData+i)->lv); INT_CPY_NEXT_FIELD( (*pData+i)->score); STD_QUERY_WHILE_END(); }