mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
72 lines
1.4 KiB
Plaintext
72 lines
1.4 KiB
Plaintext
<!--#
|
|
TechEmpower Web Framework Benchmarks
|
|
Test type 2: Single database query
|
|
-->
|
|
<!--#declaration
|
|
#include "world.h"
|
|
|
|
#ifndef AS_cpoll_cppsp_DO
|
|
static UValue* pvalue;
|
|
#endif
|
|
static World* pworld_db;
|
|
static UOrmSession* psql_db;
|
|
static UOrmStatement* pstmt_db;
|
|
|
|
static void usp_init_db()
|
|
{
|
|
U_TRACE(5, "::usp_init_db()")
|
|
|
|
pworld_db = U_NEW(World);
|
|
|
|
#ifndef AS_cpoll_cppsp_DO
|
|
pvalue = U_NEW(UValue(OBJECT_VALUE));
|
|
#endif
|
|
}
|
|
|
|
static void usp_fork_db()
|
|
{
|
|
U_TRACE(5, "::usp_fork_db()")
|
|
|
|
psql_db = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
|
|
|
|
if (psql_db->isReady())
|
|
{
|
|
pstmt_db = U_NEW(UOrmStatement(*psql_db, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
|
|
|
|
if (pstmt_db == 0) U_ERROR("usp_fork_db(): we cound't connect to db");
|
|
|
|
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 psql_db;
|
|
delete pworld_db;
|
|
#ifndef AS_cpoll_cppsp_DO
|
|
delete pvalue;
|
|
#endif
|
|
}
|
|
#endif
|
|
-->
|
|
<!--#header
|
|
Content-Type: application/json; charset=UTF-8
|
|
-->
|
|
<!--#code
|
|
pworld_db->id = u_get_num_random(10000);
|
|
|
|
pstmt_db->execute();
|
|
|
|
#ifdef AS_cpoll_cppsp_DO
|
|
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%u}", pworld_db->id, pworld_db->randomNumber);
|
|
#else
|
|
USP_JSON_stringify(*pvalue, World, *pworld_db);
|
|
#endif
|
|
-->
|