This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
DBHomework/old_src/doGetBookByObj.cpp
2017-12-28 18:18:44 +08:00

71 lines
1.5 KiB
C++

#include "bs_util.h"
using namespace std;
int main()
{
Request req;
Session se(req);
Response res;
json j;
auto jsonfail=[&](int errcode,const std::string& dtl="")
{
jsonfail_func(j,errcode,dtl);
};
do
{
if(!se.isReady())
{
jsonfail(err_session);
break;
}
if(se.getUser().empty())
{
jsonfail(err_need_login);
break;
}
if(req.requestMethod!="POST")
{
jsonfail(err_method_not_supported);
break;
}
postval(bid);
int bid_real=ParseInt(bid);
if(bid_real<0)
{
jsonfail(err_parameter,"Failed to parse BID");
break;
}
startdb();
string book_name;
if(conn.exec(make_str("select name from bs_book where class_id in (select class_id from bs_bookstatus where book_id=",bid_real,")"),
[&](MySQLResult& res)
{
res.stepRow([&](char** val,unsigned long* len)
{
j["book_name"]=string(len[0]>0?val[0]:"(NULL)");
});
})<0)
{
jsonfail(err_sql,"Step 1");
break;
}
j["success"]=1;
}
while(0);
se.writeToResponse(res);
res.content.append(j.dump());
return 0;
}