本文整理汇总了C++中CDBManager::createDBRequest方法的典型用法代码示例。如果您正苦于以下问题:C++ CDBManager::createDBRequest方法的具体用法?C++ CDBManager::createDBRequest怎么用?C++ CDBManager::createDBRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDBManager
的用法示例。
在下文中一共展示了CDBManager::createDBRequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initDB
void CAdviceBoard::initDB()
{
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequestThreads(dbManager->createDBRequest());
std::shared_ptr<CDBRequest> dbRequestPosts(dbManager->createDBRequest());
if (!dbManager->getIsConnInit())
{
CLog::getInstance()->addError("DB connect is not inited");
return;
}
const CDBRequestResult* resultThreads = dbRequestThreads->selectRequest(CDBValues("id"), "Threads");
if(dbRequestThreads->getIsLastQuerySuccess() && resultThreads != NULL && resultThreads->getRowsCnt() > 0)
{
int threadsCnt = resultThreads->getRowsCnt();
for(int j = 0; j < threadsCnt; j++)
{
int threadId = 0;
threadId = resultThreads->getIntValue(j,0);
if(threadId == 0) continue;
const CDBRequestResult* resultPosts = dbRequestPosts->selectRequest(CDBValues("id"), "Posts", "`postThreadId` = " + valueToString(threadId));
if(dbRequestPosts->getIsLastQuerySuccess() && resultPosts != NULL && resultPosts->getRowsCnt() > 0)
{
int postsCnt = resultPosts->getRowsCnt();
dbRequestPosts->updateRequest("Threads", "`threadPostsCnt` = "+valueToString(postsCnt), "`id` = "+valueToString(threadId));
}
}
}
}
示例2: buildContent
std::string CSessionsPage::buildContent() const
{
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
const CUser* user = dynamic_cast<const CUser*>(currRequest->getUser());
CTemplateHelper* templateManager = CTemplateHelper::getInstance();
std::map<std::string, std::string> params;
tmpString = "";
const CHTMLTemplate* contentTemplate = templateManager->findTemplate("content");
const CHTMLTemplate* sessionsTemplate = templateManager->findTemplate("sessionPage");
if(contentTemplate == NULL || sessionsTemplate == NULL) return "Missing content template";
const CDBRequestResult* result = dbRequest->selectRequest(CDBValues("*"), "Users");
//const CDBRequestResult* result = dbRequest->createRequest("SELECT * FROM `Users`;");
if(dbRequest->getIsLastQuerySuccess() && result != NULL && result->getRowsCnt() > 0)
{
for(int i = 0; i < result->getRowsCnt(); i++)
{
tmpString += "<tr><td>" + valueToString(result->getIntValue(i,0)) + "</td><td>" + "std::string(row[2])" + "</td><td> " + "unixTimeToDate(std::stol(row[8]))" + " </td></tr>";
}
}
params["{SESSION_LIST}"] = tmpString;
tmpString = "";
tmpString += sessionsTemplate->getHTMLData(¶ms);
params.clear();
params["{LEFTPANEL}"] = buildLeftPanel(user);
params["{UPMENU}"] = buildUpperMenu(user);
params["{CONTENT}"] = tmpString;
return contentTemplate->getHTMLData(¶ms);
}
示例3: afterFillUserData
void CSiteUser::afterFillUserData()
{
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
std::string attachStr = "";
const CDBRequestResult* result = dbRequest->selectRequest(CDBValues("attach,id"), "Files", "`userId` = " + valueToString(userId));
if (dbRequest->getIsLastQuerySuccess() && result != NULL && result->getRowsCnt() > 0)
{
for (int row = 0; row < result->getRowsCnt(); ++row)
{
attachStr += result->getStringValue(row, 0, "");
attachStr += ";";
attachStr += valueToString(result->getIntValue(row, 1, 0));
attachStr += ";";
}
}
std::vector<CAttachment*>* processedAttachs = CAttachment::processAttachmentString(attachStr);
if (processedAttachs == NULL) return;
for (auto it = processedAttachs->begin(); it != processedAttachs->end(); ++it)
{
CAttachment* currAttach = (*it);
attachments.push_back(currAttach);
}
delete processedAttachs;
}
示例4: attachFile
void CSiteUser::attachFile(const std::string& attachStr)
{
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
CDBValues dbValues;
dbValues.addValue("userId", (int)userId);
dbValues.addValue("attach", attachStr);
dbRequest->insertRequest(dbValues, "Files");
}
示例5: readFromDB
void CBan::readFromDB()
{
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
//std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
const CDBRequestResult* result = dbRequest->selectRequest(CDBValues("*"), "Bans", "`id` = "+valueToString(id));
if(dbRequest->getIsLastQuerySuccess() && result != NULL && result->getRowsCnt() > 0)
{
userId = result->getIntValue(0,1);
roTime = result->getLongValue(0,2);
isAccessClosed = result->getBoolValue(0,3);
banCreationTime = result->getLongValue(0,4);
}
}
示例6: buildContent
std::string CCatPage::buildContent() const
{
CTemplateHelper* templateManager = CTemplateHelper::getInstance();
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
std::map<std::string, std::string> params;
tmpString = "";
const CUser* user = dynamic_cast<const CUser*>(currRequest->getUser());
CConfigHelper* settingsManager = CConfigHelper::getInstance();
const CHTMLTemplate* contentTemplate = templateManager->findTemplate("content");
if(contentTemplate == NULL) return "Missing content template";
const CMenuCategory* currCategory = CMenu::getInstance()->findCategoryByName(getPageName());
if(currCategory == NULL) return "Cant find this category";
if(!user->getIsValid())return "User not valid";
const std::vector<int> threadsId = currCategory->getThreadsId(settingsManager->getIntParamValue("defaulThreadsCnt", 10));
const std::vector<int>* fixedThreadsId = user->getFixedThreads();
tmpString += "<input type='hidden' name='category_id' value='";
tmpString += valueToString(currCategory->getId());
tmpString += "' /> \n";
tmpString += "<input type='hidden' name='return_page' value='";
tmpString += getPageName();
tmpString += "' /> \n" ;
tmpString += "<h1>/";
tmpString += htmlspecialchars(currCategory->getName());
tmpString += "/ — ";
tmpString += htmlspecialchars(currCategory->getDescription());
tmpString += "</h1> \n";
if(currCategory->getThreadCreationAccessLevel() <= user->getUserType(currCategory->getId()))
{
tmpString += buildNewThreadForm(getPageName(), currCategory->getId(), user);
tmpString += "\n";
}
if(currCategory->getPostCreationAccessLevel() <= user->getUserType(currCategory->getId()))
{
tmpString += buildNewPostForm(getPageName(), user);
tmpString += "\n";
}
// GLOBAL FIXED THREADS
int threadsCnt = 0;
int hiddenthreadsCnt = 0;
const CDBRequestResult* result = dbRequest->selectRequest(CDBValues("id"),"Threads", "`threadCatId` = "+valueToString(currCategory->getId())+" AND `isFixed` = 1");
if(dbRequest->getIsLastQuerySuccess() && result != NULL && result->getRowsCnt() > 0)
{
for(int i = 0; i < result->getRowsCnt(); i++)
{
int threadId = 0;
threadId = result->getIntValue(i, 0);
const CThread* currThread = new CThread(threadId);
if(!currThread->getIsValid() || currThread->getIsHidden())
{
if(currThread->getIsHidden()) hiddenthreadsCnt++;
delete currThread;
continue;
}
threadsCnt++;
tmpString += buildThread(currThread, user);
tmpString += "\n";
delete currThread;
}
}
// USER FIXED THREADS
for(unsigned int i = 0; i < fixedThreadsId->size(); i++)
{
const CThread* currThread = new CThread((*fixedThreadsId)[i]);
if(!currThread->getIsValid() || currThread->getIsFixed() || currThread->getCatId() != currCategory->getId() || currThread->getIsHidden())
{
delete currThread;
continue;
}
threadsCnt++;
tmpString += buildThread(currThread, user);
tmpString += "\n";
delete currThread;
}
tmpString += "<br> \n";
// ALL OTHER THREADS
int minThreadPosition = INT_MAX;
for(unsigned int i = 0; i < threadsId.size(); i++)
{
const CThread* currThread = new CThread(threadsId[i]);
if(currThread->getIsValid() && currThread->getIsHidden() && !currThread->getIsFixed()) hiddenthreadsCnt++;
if(!currThread->getIsValid() || user->getIsThreadFixed(threadsId[i]) || currThread->getIsFixed() || currThread->getIsHidden())
{
delete currThread;
//.........这里部分代码省略.........
示例7: buildContent
std::string CEditPage::buildContent() const
{
CTemplateHelper* templateManager = CTemplateHelper::getInstance();
std::map<std::string, std::string> params;
std::string tmpStr = "";
const CUser* user = dynamic_cast<const CUser*>(currRequest->getUser());
if(!user->getIsValid() || !isValidId) return "";
const CHTMLTemplate* contentTemplate = templateManager->findTemplate("content");
const CHTMLTemplate* editPageTemplate = templateManager->findTemplate("editPage");
if(contentTemplate == NULL || editPageTemplate == NULL) return "Missing content template";
if(isThreadId)
{
const CThread* currThread = new CThread(id, false);
if(!currThread->getIsValid() || (user->getUserId() != currThread->getUserId() && !user->getIsModerInAnyCategories()))
{
delete currThread;
return "";
}
params["{RETURNPAGE}"] = CMenu::getInstance()->findCategoryById(currThread->getCatId())->getName();
params["{EDITTYPE}"] = isThreadId ? "thread" : "post";
params["{ID}"] = idStr;
params["{USERID}"] = valueToString(user->getUserId());
params["{TEXT}"] = currThread->getText();
params["{isHIDDEN}"] = currThread->getIsHidden() ? "true" : "false";
params["{isTHREAD}"] = "true";
//params["{ATTACHMENTS}"] = currThread->getAttachmentString();
tmpStr = editPageTemplate->getHTMLData(¶ms);
delete currThread;
}
else
{
const CPost* currPost = new CPost(id);
if(!currPost->getIsValid() || (user->getUserId() != currPost->getUserId() && !user->getIsModerInAnyCategories()))
{
delete currPost;
return "";
}
int catId = 0;
CDBManager* dbManager = CManagers::getInstance()->getDBManager();
std::shared_ptr<CDBRequest> dbRequest(dbManager->createDBRequest());
const CDBRequestResult* result = dbRequest->selectRequest(CDBValues("threadCatId"), "Threads", "`id`="+valueToString(currPost->getThreadId()), "LIMIT 1");
//MYSQL_RES* result = DBRequest.createRequest("SELECT `threadCatId` FROM `Threads` WHERE `id`="+valueToString(currPost->getThreadId())+" LIMIT 1;");
if(dbRequest->getIsLastQuerySuccess() && result != NULL && result->getRowsCnt() > 0)
{
try{ catId = result->getIntValue(0,0); }
catch(...){ catId = 0; }
}
const CMenuCategory* menuCat = CMenu::getInstance()->findCategoryById(catId);
std::string returnPage = "index";
if(menuCat != NULL) returnPage = menuCat->getName();
params["{RETURNPAGE}"] = returnPage;
params["{EDITTYPE}"] = isThreadId ? "thread" : "post";
params["{ID}"] = idStr;
params["{USERID}"] = valueToString(user->getUserId());
params["{TEXT}"] = currPost->getText();
params["{isHIDDEN}"] = "false";
params["{isTHREAD}"] = "false";
//params["{ATTACHMENTS}"] = currPost->getAttachmentString();
tmpStr = editPageTemplate->getHTMLData(¶ms);
delete currPost;
}
params.clear();
params["{LEFTPANEL}"] = buildLeftPanel(user);
params["{UPMENU}"] = buildUpperMenu(user);
params["{CONTENT}"] = tmpStr;
return contentTemplate->getHTMLData(¶ms);
}