<!--#
Test type 3: Multiple database queries
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
#include "world.h"

static uint32_t num_queries;

#ifdef U_STATIC_ORM_DRIVER_PGSQL
static void handlerResult(void* res, uint32_t num_result)
{
   U_TRACE(5, "::handlerResult(%p,%u)", res, num_result)

   U_INTERNAL_ASSERT_EQUALS(PQnfields((PGresult*)res), 1)
   U_INTERNAL_ASSERT_EQUALS(PQntuples((PGresult*)res), 1)

   char* randomNumber = U_SYSCALL(PQgetvalue, "%p,%d,%d", (PGresult*)res, 0, 0);

   if (num_result == 1) World::initResult();
   else                 World::addResult(num_result);

   World::addRandom(ntohl(*(uint32_t*)randomNumber));

   if (num_result == num_queries) World::endResult();
}
#endif

static void usp_init_query() { World::handlerInitSql(); }
static void usp_fork_query() { World::handlerForkSql(); }
-->
<!--#header
-->
<!--#code
uint32_t i = 0;

num_queries = UHTTP::getFormFirstNumericValue(1, 500);

#ifdef U_STATIC_ORM_DRIVER_PGSQL
if (World::pstmt)
   {
   while (i < num_queries) World::sendQueryPrepared(i++);

   UServer_Base::handler_db1->handlerQuery(handlerResult, num_queries);
   }
else
#endif
{
World::initResult();

for (; i < num_queries; ++i)
   {
   World::pworld_query->id = World::rnumber[i];

   World::pstmt_query->execute();

   World::handlerResult(i, World::pworld_query->randomNumber);
   }

World::endResult();
}
-->
