fortune.usp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!--#
  2. Test type 4: Fortunes
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. #include "fortune.h"
  7. static Fortune* pfortune;
  8. static UString* pmessage;
  9. static UOrmSession* psql_fortune;
  10. static UOrmStatement* pstmt_fortune;
  11. static UVector<Fortune*>* pvfortune;
  12. static void usp_fork_fortune()
  13. {
  14. U_TRACE(5, "::usp_fork_fortune()")
  15. psql_fortune = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
  16. if (psql_fortune->isReady())
  17. {
  18. pstmt_fortune = U_NEW(UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
  19. if (pstmt_fortune == 0) U_ERROR("usp_fork_fortune(): we cound't connect to db");
  20. pfortune = U_NEW(Fortune);
  21. pstmt_fortune->into(*pfortune);
  22. pmessage = U_NEW(U_STRING_FROM_CONSTANT("Additional fortune added at request time."));
  23. pvfortune = U_NEW(UVector<Fortune*>);
  24. }
  25. }
  26. #ifdef DEBUG
  27. static void usp_end_fortune()
  28. {
  29. U_TRACE(5, "::usp_end_fortune()")
  30. if (pstmt_fortune)
  31. {
  32. delete pstmt_fortune;
  33. delete psql_fortune;
  34. delete pvfortune;
  35. delete pfortune;
  36. delete pmessage;
  37. }
  38. }
  39. #endif
  40. -->
  41. <!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><!--#code
  42. Fortune* elem;
  43. unsigned char encoded[1024];
  44. pstmt_fortune->execute();
  45. pvfortune->push_back(U_NEW(Fortune(0, *pmessage)));
  46. do { pvfortune->push_back(U_NEW(Fortune(*pfortune))); } while (pstmt_fortune->nextRow());
  47. pvfortune->sort(Fortune::cmp_obj);
  48. for (uint32_t i = 0, n = pvfortune->size(); i < n; ++i)
  49. {
  50. elem = (*pvfortune)[i];
  51. USP_PRINTF_ADD(
  52. "<tr>"
  53. "<td>%u</td>"
  54. "<td>%.*s</td>"
  55. "</tr>",
  56. elem->id, u_xml_encode((const unsigned char*)U_STRING_TO_PARAM(elem->message), encoded), encoded);
  57. }
  58. pvfortune->clear();
  59. --></table></body></html>