mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-10-05 19:18:01 +08:00
95 lines
2.2 KiB
Plaintext
95 lines
2.2 KiB
Plaintext
<!--#
|
|
Test type 4: Fortunes
|
|
TechEmpower Web Framework Benchmarks
|
|
-->
|
|
<!--#declaration
|
|
#include "fortune.h"
|
|
|
|
static Fortune* pfortune;
|
|
static Fortune* pfortune2add;
|
|
static UString* pencoded;
|
|
static UOrmSession* psql_fortune;
|
|
static UOrmStatement* pstmt_fortune;
|
|
static UVector<Fortune*>* pvfortune;
|
|
|
|
static void usp_fork_fortune()
|
|
{
|
|
U_TRACE(5, "::usp_fork_fortune()")
|
|
|
|
U_NEW(UOrmSession, psql_fortune, UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
|
|
|
|
U_INTERNAL_DUMP("psql_fortune = %p", psql_fortune)
|
|
|
|
if (psql_fortune->isReady() == false)
|
|
{
|
|
U_WARNING("usp_fork_fortune(): we cound't connect to db");
|
|
|
|
return;
|
|
}
|
|
|
|
U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
|
|
|
|
if (UOrmDriver::isPGSQL()) *psql_fortune << "BEGIN ISOLATION LEVEL SERIALIZABLE; COMMIT";
|
|
|
|
U_NEW(Fortune, pfortune, Fortune);
|
|
|
|
pstmt_fortune->into(*pfortune);
|
|
|
|
U_NEW(UString, pencoded, UString(100U));
|
|
U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
|
|
U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time.")));
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
static void usp_end_fortune()
|
|
{
|
|
U_TRACE(5, "::usp_end_fortune()")
|
|
|
|
U_INTERNAL_DUMP("psql_fortune = %p", psql_fortune)
|
|
|
|
delete psql_fortune;
|
|
|
|
if (pstmt_fortune)
|
|
{
|
|
delete pstmt_fortune;
|
|
delete pfortune;
|
|
delete pencoded;
|
|
delete pvfortune;
|
|
delete pfortune2add;
|
|
}
|
|
}
|
|
#endif
|
|
-->
|
|
<!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><!--#code
|
|
Fortune* item;
|
|
|
|
U_NEW(Fortune, item, Fortune(*pfortune2add));
|
|
pvfortune->push_back(item);
|
|
|
|
pstmt_fortune->execute();
|
|
|
|
do {
|
|
U_NEW(Fortune, item, Fortune(*pfortune));
|
|
pvfortune->push_back(item);
|
|
}
|
|
while (pstmt_fortune->nextRow());
|
|
|
|
pvfortune->sort(Fortune::cmp_obj);
|
|
|
|
for (uint32_t i = 0, n = pvfortune->size(); i < n; ++i)
|
|
{
|
|
Fortune* elem = (*pvfortune)[i];
|
|
|
|
UXMLEscape::encode(elem->message, *pencoded);
|
|
|
|
USP_PRINTF_ADD(
|
|
"<tr>"
|
|
"<td>%u</td>"
|
|
"<td>%v</td>"
|
|
"</tr>",
|
|
elem->id, pencoded->rep);
|
|
}
|
|
|
|
pvfortune->clear();
|
|
--></table></body></html>
|