//------------------------------------------------------------------------------------- bool DBInterfaceMysql::query(const char* cmd, uint32 size, bool showExecInfo, MemoryStream * result) { if(pMysql_ == NULL) { if(showExecInfo) { ERROR_MSG(fmt::format("DBInterfaceMysql::query: has no attach(db).sql:({})\n", lastquery_)); } if(result) write_query_result(result); return false; } querystatistics(cmd, size); lastquery_.assign(cmd, size); if(_g_debug) { DEBUG_MSG(fmt::format("DBInterfaceMysql::query({:p}): {}\n", (void*)this, lastquery_)); } int nResult = mysql_real_query(pMysql_, cmd, size); if(nResult != 0) { if(showExecInfo) { ERROR_MSG(fmt::format("DBInterfaceMysql::query: is error({}:{})!\nsql:({})\n", mysql_errno(pMysql_), mysql_error(pMysql_), lastquery_)); } this->throwError(); if(result) write_query_result(result); return false; } else { if(showExecInfo) { INFO_MSG("DBInterfaceMysql::query: successfully!\n"); } } return result == NULL || write_query_result(result); }
//------------------------------------------------------------------------------------- bool DBInterfaceRedis::query(const char* cmd, uint32 size, bool printlog, MemoryStream * result) { KBE_ASSERT(pRedisContext_); redisReply* pRedisReply = (redisReply*)redisCommand(pRedisContext_, cmd); lastquery_ = cmd; RedisWatcher::querystatistics(lastquery_.c_str(), (uint32)lastquery_.size()); write_query_result(pRedisReply, result); if (pRedisContext_->err) { if(printlog) { ERROR_MSG(fmt::format("DBInterfaceRedis::query: cmd={}, errno={}, error={}\n", cmd, pRedisContext_->err, pRedisContext_->errstr)); } if(pRedisReply) freeReplyObject(pRedisReply); this->throwError(NULL); return false; } freeReplyObject(pRedisReply); if(printlog) { INFO_MSG("DBInterfaceRedis::query: successfully!\n"); } return true; }