<!--#
Test type 2: Single database query
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
#include "world.h"

static World*         pworld_db;
static UOrmSession*   psql_db;
static UOrmStatement* pstmt_db;

static void usp_fork_db()
{
   U_TRACE(5, "::usp_fork_db()")

   U_NEW(UOrmSession, psql_db, UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));

   if (psql_db->isReady() == false)
      {
      U_WARNING("usp_fork_db(): we cound't connect to db");

      delete psql_db;
             psql_db = U_NULLPTR;

      return;
      }

   U_NEW(UOrmStatement, pstmt_db, UOrmStatement(*psql_db, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));

   U_NEW(World, pworld_db, World);

   pstmt_db->use( pworld_db->id);
   pstmt_db->into(pworld_db->randomNumber);
}

#ifdef DEBUG
static void usp_end_db()
{
   U_TRACE(5, "::usp_end_db()")

   if (pstmt_db)
      {
      delete pstmt_db;
      delete pworld_db;
      delete psql_db;
      }
}
#endif
-->
<!--#header
Content-Type: application/json
-->
<!--#code
pworld_db->id = u_get_num_random(10000-1);

pstmt_db->execute();

#ifdef AS_cpoll_cppsp_DO
char* ptr = UClientImage_Base::wbuffer->pend();

u_put_unalignedp32(ptr,   U_MULTICHAR_CONSTANT32('{','"','i','d'));
u_put_unalignedp16(ptr+4, U_MULTICHAR_CONSTANT16('"',':'));

ptr = u_num2str32(pworld_db->id, ptr+6);

u_put_unalignedp64(ptr,   U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));

ptr = u_num2str32(pworld_db->randomNumber, ptr+16);

*ptr++ = '}';

UClientImage_Base::wbuffer->size_adjust(ptr);
#else
USP_OBJ_JSON_stringify(*pworld_db);
#endif
-->
