12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <!--#
- Test type 4: Fortunes
- TechEmpower Web Framework Benchmarks
- -->
- <!--#declaration
- #include "fortune.h"
- static Fortune* pfortune;
- static UString* pmessage;
- static UOrmSession* psql_fortune;
- static UOrmStatement* pstmt_fortune;
- static UVector<Fortune*>* pvfortune;
- static void usp_fork_fortune()
- {
- U_TRACE(5, "::usp_fork_fortune()")
- psql_fortune = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
- if (psql_fortune->isReady())
- {
- pstmt_fortune = U_NEW(UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
- if (pstmt_fortune == 0) U_ERROR("usp_fork_fortune(): we cound't connect to db");
- pfortune = U_NEW(Fortune);
- pstmt_fortune->into(*pfortune);
- pmessage = U_NEW(U_STRING_FROM_CONSTANT("Additional fortune added at request time."));
- pvfortune = U_NEW(UVector<Fortune*>);
- }
- }
- #ifdef DEBUG
- static void usp_end_fortune()
- {
- U_TRACE(5, "::usp_end_fortune()")
- if (pstmt_fortune)
- {
- delete pstmt_fortune;
- delete psql_fortune;
- delete pvfortune;
- delete pfortune;
- delete pmessage;
- }
- }
- #endif
- -->
- <!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><!--#code
- Fortune* elem;
- unsigned char encoded[1024];
- pstmt_fortune->execute();
- pvfortune->push_back(U_NEW(Fortune(0, *pmessage)));
- do { pvfortune->push_back(U_NEW(Fortune(*pfortune))); } while (pstmt_fortune->nextRow());
- pvfortune->sort(Fortune::cmp_obj);
- for (uint32_t i = 0, n = pvfortune->size(); i < n; ++i)
- {
- elem = (*pvfortune)[i];
- USP_PRINTF_ADD(
- "<tr>"
- "<td>%u</td>"
- "<td>%.*s</td>"
- "</tr>",
- elem->id, u_xml_encode((const unsigned char*)U_STRING_TO_PARAM(elem->message), encoded), encoded);
- }
- pvfortune->clear();
- --></table></body></html>
|