Variant f_mysql_async_query_result(CVarRef link_identifier) { MySQL* mySQL = MySQL::Get(link_identifier); if (!mySQL) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return Variant(Variant::NullInit()); } MYSQL* conn = mySQL->get(); if (!conn || (conn->async_op_status != ASYNC_OP_QUERY && conn->async_op_status != ASYNC_OP_UNSET)) { raise_warning("runtime/ext_mysql: attempt to check query result when query " "not executing"); return Variant(Variant::NullInit()); } int error = 0; auto status = mysql_real_query_nonblocking( conn, mySQL->m_async_query.data(), mySQL->m_async_query.size(), &error); if (status != NET_ASYNC_COMPLETE) { return Variant(Variant::NullInit()); } if (error) { return Variant(Variant::NullInit()); } mySQL->m_async_query.reset(); MYSQL_RES* mysql_result = mysql_use_result(conn); MySQLResult *r = NEWOBJ(MySQLResult)(mysql_result); r->setAsyncConnection(mySQL); Resource ret(r); return ret; }
bool MySQL::CloseConn(const Variant& link_identifier) { MySQL *mySQL = Get(link_identifier); if (mySQL && !mySQL->isPersistent()) { mySQL->close(); } return true; }
int main ( ) { /* Create MySQL object */ MySQL sql; /* Open Database */ std::cout << "Connecting to 'localhost' using 'test' database" << std::endl; assert ( sql.connect ( "localhost", "root", "blue23", "test" ) == true ); std::cout << "Opening was successful" << std::endl; /* Create a table */ std::cout << "Creating table tbl1 (one int, two int)" << std::endl; assert ( sql.exec ( "create table tbl1 (one int, two int);" ) == 1 ); std::cout << "Created table tbl1" << std::endl; /* Insert values */ std::cout << "Insert values ( 10, 10 ) into tbl1" << std::endl; assert ( sql.exec ( "insert into tbl1 (one, two) VALUES ( 10, 10 )" ) == 1 ); std::cout << "Inserted values successfully" << std::endl; /* Query values */ std::cout << "Query values to make sure of integraty" << std::endl; assert ( sql.query ( "select * from tbl1" ) == 1); std::cout << "Query was successful" << std::endl; /* Integraty of values */ std::cout << "Checking to see if query returned results" << std::endl; assert ( sql.hasNext ( ) ); std::cout << "Results were returned" << std::endl; /* Check to see that we get a total of two columns ( one, two ) from query */ std::cout << "Checking to see if a record has two entries ( one, two )" << std::endl; std::vector<std::string> l = sql.next ( ); assert( l.size() == 2 ); std::cout << "Integraty was achieved for record count" << std::endl; /* Check Integraty of inserted row ( 10, 10 ) */ std::cout << "Checking to see one = 10" << std::endl; assert( l[0].compare ( "10" ) == 0 ); std::cout << "Checking to see two = 10" << std::endl; assert( l[1].compare ( "10" ) == 0 ); /* Clear out values */ std::cout << "Clearing values from database" << std::endl; assert ( sql.query ( "delete from tbl1" ) == 1 ); std::cout << "Database values were cleared" << std::endl; /* Remove table */ std::cout << "Removing table tbl1 from database" << std::endl; assert ( sql.query ( "DROP TABLE IF EXISTS tbl1" ) == 1); std::cout << "Table tbl1 was removed from database" << std::endl; /* Close database */ std::cout << "Database attempting to close" << std::endl; sql.disconnect (); std::cout << "Database closed" << std::endl; /* Closing statements */ std::cout << "Finished unit testing :D" << std::endl; return 1; };
int64_t f_mysql_async_status(CVarRef link_identifier) { MySQL *mySQL = MySQL::Get(link_identifier); if (!mySQL || !mySQL->get()) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return -1; } return mySQL->get()->async_op_status; }
static int64_t HHVM_FUNCTION(mysql_async_status, const Variant& link_identifier) { MySQL *mySQL = MySQL::Get(link_identifier); if (!mySQL || !mySQL->get()) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return -1; } return mySQL->get()->async_op_status; }
Variant f_mysql_warning_count(CVarRef link_identifier /* = null */) { MySQL *mySQL = MySQL::Get(link_identifier); if (!mySQL) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return false; } MYSQL *conn = mySQL->get(); if (conn) { return (int64_t)mysql_warning_count(conn); } return false; }
void UserModule::ajaxIsEmailExist(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String email = request.header.POST.getValue("email"); String sql = (String)"select id from users where (email='" + email + "')"; string sql8 = sql.to_string(); if (query->active(sql) > 0) { page->tplIndex->out("out", "<note>\n<result>1</result></note>\n"); } manager->deleteQuery(query); }
MySQL* ConnectionPool::init_connect() { MySQL *query = new MySQL(); if (!query->init()) { printf("!query->init()\n"); return NULL; } if (!query->connect("127.0.0.1", "root", "", "sitev")) { printf("!query->connect()\n"); return NULL; } query->exec("SET NAMES utf8"); return query; }
void WidgetManager::paintPageWidgets(WebPage *page) { if (page == NULL) return; MySQL *query = page->site->manager->newQuery(); String sql = "select widgetId, tag from widget_site where siteId='" + (String)page->site->siteId + "'"; if (query->active(sql)) { int count = query->getRowCount(); for (int i = 0; i < count; i++) { int widgetId = query->getFieldValue(i, "widgetId").toInt(); String tag = query->getFieldValue(i, "tag"); paintWidget(page, tag, widgetId); } } }
String WebModule::getModuleUrl() { MySQL *query = manager->newQuery(); String sql = "select * from modules where id='" + (String)moduleId + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String url = query->getFieldValue(0, "url"); return url; } } } return ""; }
Variant f_mysql_errno(const Variant& link_identifier /* = null */) { MySQL *mySQL = MySQL::Get(link_identifier); if (!mySQL) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return false; } MYSQL *conn = mySQL->get(); if (conn) { return (int64_t)mysql_errno(conn); } if (mySQL->m_last_error_set) { return (int64_t)mySQL->m_last_errno; } return false; }
Variant f_mysql_error(CVarRef link_identifier /* = null */) { MySQL *mySQL = MySQL::Get(link_identifier); if (!mySQL) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return false; } MYSQL *conn = mySQL->get(); if (conn) { return String(mysql_error(conn), CopyString); } if (mySQL->m_last_error_set) { return String(mySQL->m_last_error); } return false; }
void StaticPageModule::paint(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String sql = "select txt.value from data d, dataText txt where d.dataId=txt.id and d.pageId='" + (String)page->pageId + "'"; printf("sql = %s\n", sql.toString8().c_str()); if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String content = query->getFieldValue(0, "value"); page->out("content", content); } } } }
void NewsModule::ajax(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String obj = request.header.GET.getValue("p1"); String func = request.header.GET.getValue("p2"); String uuid = request.header.COOKIE.getValue("uuid"); if (obj == "post") { if (func == "sendComment") { String comment = request.header.POST.getValue("comment"); int newsId = request.header.POST.getValue("newsId").toInt(); int userId = manager->getUserId(uuid); String result = ""; String sql = "insert into comments (userId, newsId, comment) values ('" + (String)userId + "', '" + (String)newsId + "', '" + comment + "')"; if (query->exec(sql)) { result = "1"; } page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<result>" + result + "</result>\n"); page->tplIndex->out("out", "</note>\n"); } if (func == "sendPost") { String name = request.header.POST.getValue("name"); String text = request.header.POST.getValue("content"); text = request.header.htmlEntitiesDecode(text.toString8()); int userId = manager->getUserId(uuid); String result = ""; String sql = "insert into dataNews (name, text) values ('" + name + "', '" + text + "')"; if (query->exec(sql)) { sql = "insert into data (pageId, dataId, moduleId, userId) values('" + (String)page->pageId + "', LAST_INSERT_ID(), '3', '" + (String)userId + "')"; if (query->exec(sql)) { result = "1"; } else result = "3"; } else result = "2"; page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<result>" + result + "</result>\n"); page->tplIndex->out("out", "<sql>" + sql + "</sql>\n"); page->tplIndex->out("out", "</note>\n"); } } }
void UserModule::activate(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String p3 = request.header.GET.getValue("p3"); String sql = "update users set active = '1', password=newPassword where uuid = '" + p3 + "'"; WebTemplate * tpl = new WebTemplate(); String activateTpl = ""; if (query->exec(sql)) { activateTpl = "activateSuccess_tpl.html"; } else { activateTpl = "activateFail_tpl.html"; } if (tpl->open(manager->modulePath + "/user/" + activateTpl)) { tpl->exec(); page->out("content", tpl->html); } manager->deleteQuery(query); }
MYSQL *MySQL::GetConn(const Variant& link_identifier, MySQL **rconn /* = NULL */) { MySQL *mySQL = Get(link_identifier); MYSQL *ret = nullptr; if (mySQL) { ret = mySQL->get(); } if (ret == nullptr) { raise_warning("supplied argument is not a valid MySQL-Link resource"); } // Don't return a connection where mysql_real_connect() failed to most // f_mysql_* APIs (the ones that deal with errno where we do want to do this // anyway use MySQL::Get instead) as mysqlclient doesn't support passing // connections in that state and it can crash. if (mySQL && mySQL->m_last_error_set) { ret = nullptr; } else if (rconn) { *rconn = mySQL; } return ret; }
bool f_mysql_async_connect_completed(CVarRef link_identifier) { MySQL* mySQL = MySQL::Get(link_identifier); if (!mySQL) { raise_warning("supplied argument is not a valid MySQL-Link resource"); return true; } MYSQL* conn = mySQL->get(); if (conn->async_op_status != ASYNC_OP_CONNECT) { // Don't warn if we're in UNSET state (ie between queries, etc) if (conn->async_op_status != ASYNC_OP_UNSET) { raise_warning("runtime/ext_mysql: no pending async connect in progress"); } return true; } int error = 0; auto status = mysql_real_connect_nonblocking_run(conn, &error); return status == NET_ASYNC_COMPLETE; }
void NewsModule::paintTags(WebPage *page, String num, WebTemplate *tpl) { WebTemplate *tplTag = new WebTemplate(); if (tplTag->open(manager->modulePath + "/" + url + "/tag_tpl.html")) { MySQL *query = manager->newQuery(); String sql = "select tag1, tag2, tag3, tag4, tag5 from dataNews n, data d where d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' and n.num='" + num + "' order by n.num desc"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { for (int i = 1; i <= 5; i++) { String tag = query->getFieldValue(0, "tag" + (String)i); if (tag != "") { tplTag->out("name", tag); tplTag->exec(); tpl->out("tags", tplTag->html); } } } } } } }
void WebModule::setOptionsFromDB(int moduleId) { this->moduleId = moduleId; MySQL *query = manager->newQuery(); String sql = "select * from modules where id='" + (String)moduleId + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { name = query->getFieldValue(0, "name"); about = query->getFieldValue(0, "about"); url = query->getFieldValue(0, "url"); return; } } } }
void UserModule::sendAccount(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String guid = generateUUID(); String email = request.header.POST.getValue("email"); String login = request.header.POST.getValue("login"); if (email != "") { String password = manager->generateUserPassword(); String sql = "select * from users where email='" + email + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { guid = query->getFieldValue(0, "uuid"); sql = "update users set newPassword='******', uuid='" + guid + "' where email='" + email + "'"; if (query->exec(sql)) {} } else { sql = "insert into users (email, login, newPassword, uuid) values('" + email + "', '" + login + "', '" + password + "', '" + guid + "')"; if (query->exec(sql)) {} } } } WebTemplate * tplEmail = new WebTemplate(); String userTpl = "email_tpl.html"; if (tplEmail->open(manager->modulePath + "/user/" + userTpl)) { tplEmail->out("host", page->site->host); tplEmail->out("email", email); tplEmail->out("password", password); tplEmail->out("guid", guid); tplEmail->exec(); sendMail(email, "no-reply@" + page->site->host, page->site->host + ": подтверждение аккаунта", tplEmail->html); } WebTemplate * tpl = new WebTemplate(); if (tpl->open(manager->modulePath + "/user/loginSendAccount_tpl.html")) { tpl->out("out", email); tpl->exec(); page->out("content", tpl->html); } } manager->deleteQuery(query); }
void NewsModule::paintNewsItemView(WebPage *page, HttpRequest &request, String num) { MySQL *query = manager->newQuery(); String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); String sql = "select dt, name, about, text, n.num, n.id newsId from dataNews n, data d where d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' and n.num='" + num + "' order by n.num desc"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { WebTemplate * tpl = new WebTemplate(); if (tpl->open(manager->modulePath + "/" + url + "/view_tpl.html")) { String dt = query->getFieldValue(0, "dt"); dt = dtRus(dt, 0); String name = query->getFieldValue(0, "name"); String about = query->getFieldValue(0, "about"); String text = query->getFieldValue(0, "text"); //String num = query->getFieldValue(0, "num"); int newsId = query->getFieldValue(0, "newsId").toInt(); tpl->out("dt", dt); tpl->out("name", name); tpl->out("text", text); tpl->out("num", num); tpl->out("itemId", newsId); paintTags(page, num, tpl); sql = "select c.dt, c.comment, u.login from comments c, users u where u.id=c.userId and newsId='" + (String)newsId + "' order by c.id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); for (int i = 0; i < count; i++) { String dt = query->getFieldValue(i, "dt"); String comment = query->getFieldValue(i, "comment"); String login = query->getFieldValue(i, "login"); WebTemplate * tplCommentItem = new WebTemplate(); if (tplCommentItem->open(manager->modulePath + "/" + url + "/commentItem_tpl.html")) { tplCommentItem->out("login", login); tplCommentItem->out("dt", dt); tplCommentItem->out("comment", comment); tplCommentItem->exec(); tpl->out("comments", tplCommentItem->html); } } } } WebTemplate * tplSendComment = new WebTemplate(); if (userId != 0) { if (tplSendComment->open(manager->modulePath + "/" + url + "/sendComment_tpl.html")) { tplSendComment->out("newsId", newsId); } } else { if (tplSendComment->open(manager->modulePath + "/" + url + "/sendCommentNotEnter_tpl.html")) { tplSendComment->out("newsId", newsId); } } tplSendComment->exec(); tpl->out("sendComment", tplSendComment->html); tpl->exec(); page->out("title", name); page->out("keywords", name); page->out("description", name); page->out("content", tpl->html); } } } } }
void UserModule::ajax(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String obj = request.header.GET.getValue("p1"); String func = request.header.GET.getValue("p2"); String uuid = request.header.COOKIE.getValue("uuid"); if (obj == "user") { if (func == "login") { String login = request.header.POST.getValue("login"); String password = request.header.POST.getValue("password"); String chkSave = request.header.POST.getValue("chkSave"); page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<login>" + login + "</login>\n"); String sql = (String)"select * from users where (email='" + login + "' or login='******') and password='******'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String userId = query->getFieldValue(0, "id"); // if (userId == 1) { if (true) { String sql = (String)"insert into uuid (uuid, userId, sec) values ('" + uuid + "', '" + userId + "', '10000')"; if (chkSave == "") sql = (String)"insert into uuid (uuid, userId, sec) values ('" + uuid + "', '" + userId + "', '0')"; if (query->exec(sql)) { page->tplIndex->out("out", "<result>" + ((String)1) + "</result>\n"); } bool flag = false; sql = "select serviceId, u.id from uuidPartner up, users u where isnull(up.deleted) and up.userId=u.id and cookie='" + uuid + "' order by u.id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { flag = true; String ref = query->getFieldValue(0, "id"); String serviceId = query->getFieldValue(0, "serviceId"); sql = "select * from users where id='" + userId + "' and isnull(ref" + serviceId + ")"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { //String ref1_1 = query->getFieldValue(0, "ref1_1"); sql = "update users set ref" + serviceId + "='" + ref + "' where id='" + userId + "'"; query->exec(sql); for (int i = 1; i <= 4; i++) { String si = i; sql = "update users set ref" + serviceId + "_" + si + "=ref" + serviceId + "_" + si + "+1 where id='" + ref + "'"; query->exec(sql); sql = "select * from users where id='" + ref + "' and ref1<>id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { ref = query->getFieldValue(0, "ref" + serviceId); } else break; } } } } } } sql = "update uuidPartner set deleted=1 where cookie='" + uuid + "'"; query->exec(sql); } } } if (flag == false) { sql = "update users set ref1=0 where id='" + userId + "'"; query->exec(sql); } } else { page->tplIndex->out("out", "<error>���� �������� ������������ - ���� � ������ ����������...</error>"); } } } } page->tplIndex->out("out", "</note>\n"); } else if (func == "logout") { if (uuid != "") { int userId = manager->getUserId(uuid); String sql = (String)"delete from uuid where userId='" + (String)userId + "'"; if (query->exec(sql)) { page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<result>1</result>"); page->tplIndex->out("out", "</note>\n"); } } } else if (func == "isEmailExist") ajaxIsEmailExist(page, request); } manager->deleteQuery(query); }
void UserModule::changePassword(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); WebTemplate * tpl = new WebTemplate(); String p3 = request.header.GET.getValue("p3"); if (p3 == "") { if (userId != 0) { if (tpl->open(manager->modulePath + "/2/changePassword_tpl.html")) { tpl->exec(); page->out("out", tpl->html); } } else { if (tpl->open(manager->documentRoot + "/tpl/message_tpl.html")) { tpl->out("caption", "����� ������"); tpl->out("error", "��� ����� ������ ������� �� ���� ��� ����� ������� � ������ �������"); tpl->exec(); page->out("out", tpl->html); } } } else if (p3 == "done") { if (tpl->open(manager->documentRoot + "/tpl/message_tpl.html")) { tpl->out("caption", "����� ������"); String message, error; if (userId != 0) { String oldPassword = request.header.POST.getValue("oldPassword"); String sql = "select * from users where id='" + (String)userId + "' and password='******'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String newPassword = request.header.POST.getValue("newPassword"); String repeatPassword = request.header.POST.getValue("repeatPassword"); error = manager->isPasswordCorrect(newPassword); if (error == "") { if (newPassword == repeatPassword) { String sql = "update users set password='******' where id='" + userId + "'"; if (query->exec(sql)) { message = "������ ��� ������� ������!"; } else { error = "������ ���� ������"; } } else error = "������ �� ���������"; } } else error = "������ ������ ����� �� ���������"; } } } else { error = "��� ����� ������ ������� �� ���� ��� ����� ������� � ������ �������"; } tpl->out("message", message); tpl->out("error", error); tpl->exec(); page->out("out", tpl->html); } } }
// This function takes an array of arrays, each of which is of the // form array($dbh, ...). The only thing that matters in the inner // arrays is the first element being a MySQL instance. It then // procedes to block for up to 'timeout' seconds, waiting for the // first actionable descriptor(s), which it then returns in the form // of the original arrays passed in. The intention is the caller // would include other information they care about in the tail of the // array so they can decide how to act on the // potentially-now-queryable descriptors. // // This function is a poor shadow of how the async library can be // used; for more complex cases, we'd use libevent and share our event // loop with other IO operations such as memcache ops, thrift calls, // etc. That said, this function is reasonably efficient for most use // cases. Variant f_mysql_async_wait_actionable(CVarRef items, double timeout) { size_t count = items.toArray().size(); if (count == 0 || timeout < 0) { return Array::Create(); } struct pollfd* fds = (struct pollfd*)calloc(count, sizeof(struct pollfd)); SCOPE_EXIT { free(fds); }; // Walk our input, determine what kind of poll() operation is // necessary for the descriptor in question, and put an entry into // fds. int nfds = 0; for (ArrayIter iter(items.toArray()); iter; ++iter) { Array entry = iter.second().toArray(); if (entry.size() < 1) { raise_warning("element %d did not have at least one entry", nfds); return Array::Create(); } MySQL* mySQL = entry.rvalAt(0).toResource().getTyped<MySQL>(); MYSQL* conn = mySQL->get(); if (conn->async_op_status == ASYNC_OP_UNSET) { raise_warning("runtime/ext_mysql: no pending async operation in " "progress"); return Array::Create(); } pollfd* fd = &fds[nfds++]; fd->fd = mysql_get_file_descriptor(conn); if (conn->net.async_blocking_state == NET_NONBLOCKING_READ) { fd->events = POLLIN; } else { fd->events = POLLOUT; } fd->revents = 0; } // The poll itself; either the timeout is hit or one or more of the // input fd's is ready. int timeout_millis = static_cast<long>(timeout * 1000); int res = poll(fds, nfds, timeout_millis); if (res == -1) { raise_warning("unable to poll [%d]: %s", errno, folly::errnoStr(errno).c_str()); return Array::Create(); } // Now just find the ones that are ready, and copy the corresponding // arrays from our input array into our return value. Array ret = Array::Create(); nfds = 0; for (ArrayIter iter(items.toArray()); iter; ++iter) { Array entry = iter.second().toArray(); if (entry.size() < 1) { raise_warning("element %d did not have at least one entry", nfds); return Array::Create(); } MySQL* mySQL = entry.rvalAt(0).toResource().getTyped<MySQL>(); MYSQL* conn = mySQL->get(); pollfd* fd = &fds[nfds++]; if (fd->fd != mysql_get_file_descriptor(conn)) { raise_warning("poll returned events out of order wtf"); continue; } if (fd->revents != 0) { ret.append(iter.second()); } } return ret; }
void NewsModule::paintNews(WebPage *page, HttpRequest &request) { WebTemplate *tpl = new WebTemplate(); if (!tpl->open(manager->modulePath + "/" + url + "/index_tpl.html")) return; WebTemplate *tplItem = new WebTemplate(); if (!tplItem->open(manager->modulePath + "/" + url + "/item_tpl.html")) return; WebTemplate *tplLast = new WebTemplate(); if (!tplLast->open(manager->modulePath + "/" + url + "/itemLast_tpl.html")) return; WebTemplate *tplTag = new WebTemplate(); if (!tplTag->open(manager->modulePath + "/" + url + "/tag_tpl.html")) return; MySQL *query = manager->newQuery(); String sql = "select count(*) cnt from dataNews n, data d where not isnull(num) and d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' order by dt desc"; int newsCount = 0; if (query->active(sql) > 0) { newsCount = query->getFieldValue(0, "cnt").toInt(); } int p = request.header.GET.getValue("p").toInt(); sql = "select * from dataNews n, data d where not isnull(num) and d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' order by dt desc limit " + (String)(p * 10) + ", 10"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); for (int i = 0; i < count; i++) { String id = query->getFieldValue(i, "id"); String dt = query->getFieldValue(i, "dt"); dt = dtRus(dt, 0); String name = query->getFieldValue(i, "name"); String about = query->getFieldValue(i, "about"); String text = query->getFieldValue(i, "text"); int num = query->getFieldValue(i, "num").toInt(); String tag1 = query->getFieldValue(i, "tag1"); String tag2 = query->getFieldValue(i, "tag2"); String tag3 = query->getFieldValue(i, "tag3"); String tag4 = query->getFieldValue(i, "tag4"); String tag5 = query->getFieldValue(i, "tag5"); WebTemplate *tpli = tplItem; if (i + 1 == count) tpli = tplLast; tpli->clearAllTags(); tpli->out("page", page->page); tpli->out("num", num); tpli->out("itemId", id); tpli->out("dt", dt); tpli->out("name", name); tpli->out("about", about); tpli->out("text", text); tpli->out("host", page->site->host); tplTag->clearAllTags(); tplTag->out("tag1", tag1); tplTag->out("tag2", tag2); tplTag->out("tag3", tag3); tplTag->out("tag4", tag4); tplTag->out("tag5", tag5); tplTag->exec(); tpli->out("tags", tplTag->html); tpli->exec(); tpl->out("out", tpli->html); } } } if (newsCount != 0) { WebTemplate *tplPag = new WebTemplate(); if (!tplPag->open(manager->modulePath + "/" + url + "/pagination_tpl.html")) return; int pageCount = newsCount / 10; if (newsCount % 10 != 0) pageCount++; for (int i = 0; i < pageCount; i++) { if (i == 0) tplPag->out("out", "<li><a href=\"/\">" + (String)(i + 1) + "</a></li>"); else tplPag->out("out", "<li><a href=\"/post?p=" + (String)i + "\">" + (String)(i + 1) + "</a></li>"); if (i + 1 == pageCount) tplPag->out("next", "/post?p=" + (String)i); } tplPag->exec(); tpl->out("out", tplPag->html); } String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); WebTemplate *tplWrite = new WebTemplate(); if (userId != 0) { if (!tplWrite->open(manager->modulePath + "/" + url + "/addPostButton_tpl.html")) return; } else { if (!tplWrite->open(manager->modulePath + "/" + url + "/addPostButtonNotEnter_tpl.html")) return; } tplWrite->exec(); tpl->out("out", tplWrite->html); tpl->out("caption", caption); tpl->exec(); page->out("content", tpl->html); }
int main(int argc, char **argv) { const char *user = argc > 1 ? argv[1] : ""; const char *pass = argc > 2 ? argv[2] : ""; const char *db = argc > 3 ? argv[3] : "test"; const char *sock = argc > 4 ? argv[4] : "/var/lib/mysql/mysql.sock"; MySQL mysql; mysql.connectUnix(sock, db, user, pass); cerr << "connected\n"; MySQL::result res = mysql.query("SELECT * FROM xmpp_users WHERE username = '******'", "alex"); for(; ! res.eof(); res.next()) { cout << res["username"] << endl; } res.free(); mysql.close(); return 0; }