本文整理汇总了C++中PostgresStrings类的典型用法代码示例。如果您正苦于以下问题:C++ PostgresStrings类的具体用法?C++ PostgresStrings怎么用?C++ PostgresStrings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PostgresStrings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: v_count_age_owners
uint32_t v_count_age_owners(uint32_t ageInfoId)
{
PostgresStrings<2> parms;
parms.set(0, ageInfoId);
parms.set(1, DS::Vault::e_AgeOwnersFolder);
PGresult* result = PQexecParams(s_postgres,
"SELECT idx FROM vault.find_folder($1, $2);",
2, 0, parms.m_values, 0, 0, 0);
uint32_t owners = 0;
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return owners;
}
parms.set(0, PQgetvalue(result, 0, 0));
PQclear(result);
result = PQexecParams(s_postgres,
"SELECT COUNT(*) FROM vault.\"NodeRefs\" WHERE \"ParentIdx\"=$1",
1, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) == PGRES_TUPLES_OK) {
owners = strtoul(PQgetvalue(result, 0, 0), 0, 10);
} else {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
}
PQclear(result);
return owners;
}
示例2: v_send_node
DS::Vault::NodeRef v_send_node(uint32_t nodeId, uint32_t playerId, uint32_t senderId)
{
DS::Vault::NodeRef ref;
ref.m_child = ref.m_owner = ref.m_parent = 0;
PostgresStrings<2> parms;
parms.set(0, playerId);
parms.set(1, DS::Vault::e_InboxFolder);
PGresult* result = PQexecParams(s_postgres,
"SELECT idx FROM vault.find_folder($1, $2);",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return ref;
}
DS_DASSERT(PQntuples(result) == 1);
uint32_t inbox = strtoul(PQgetvalue(result, 0, 0), 0, 10);
PQclear(result);
if (v_ref_node(inbox, nodeId, senderId)) {
ref.m_child = nodeId;
ref.m_owner = senderId;
ref.m_parent = inbox;
}
return ref;
}
示例3: v_has_node
bool v_has_node(uint32_t parentId, uint32_t childId)
{
if (parentId == 0)
return false;
if (parentId == childId)
return true;
PostgresStrings<2> parms;
parms.set(0, parentId);
parms.set(1, childId);
check_postgres();
PGresult* result = PQexecParams(s_postgres,
"SELECT vault.has_node($1, $2)",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
DS_DASSERT(PQntuples(result) == 1);
bool retval = (*PQgetvalue(result, 0, 0) == 't');
PQclear(result);
return retval != 0;
}
示例4: v_fetch_tree
bool v_fetch_tree(uint32_t nodeId, std::vector<DS::Vault::NodeRef>& refs)
{
PostgresStrings<1> parm;
parm.set(0, nodeId);
PGresult* result = PQexecParams(s_postgres,
"SELECT \"ParentIdx\", \"ChildIdx\", \"OwnerIdx\", \"Seen\""
" FROM vault.fetch_tree($1);",
1, 0, parm.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
refs.resize(PQntuples(result));
for (size_t i=0; i<refs.size(); ++i) {
refs[i].m_parent = strtoul(PQgetvalue(result, i, 0), 0, 10);
refs[i].m_child = strtoul(PQgetvalue(result, i, 1), 0, 10);
refs[i].m_owner = strtoul(PQgetvalue(result, i, 2), 0, 10);
refs[i].m_seen = strtoul(PQgetvalue(result, i, 3), 0, 10);
}
PQclear(result);
return true;
}
示例5: v_find_public_ages
bool v_find_public_ages(const DS::String& ageFilename, std::vector<Auth_PubAgeRequest::NetAgeInfo>& ages)
{
PostgresStrings<2> parms;
parms.set(0, DS::Vault::e_NodeAgeInfo);
parms.set(1, ageFilename);
// ageInfoId, Uuid, InstName, UserName, Description, SeqNumber, Language
PGresult* result = PQexecParams(s_postgres,
"SELECT idx, \"Uuid_1\", \"String64_3\", \"String64_4\","
" \"Text_1\",\"Int32_1\", \"Int32_3\" FROM vault.\"Nodes\""
" WHERE \"NodeType\"=$1 AND \"Int32_2\"=1 AND \"String64_2\"=$2"
" ORDER BY \"ModifyTime\" LIMIT 50",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
for (int i = 0; i < PQntuples(result); ++i) {
Auth_PubAgeRequest::NetAgeInfo ai;
ai.m_instance = DS::Uuid(PQgetvalue(result, i, 1));
ai.m_instancename = PQgetvalue(result, i, 2);
ai.m_username = PQgetvalue(result, i, 3);
ai.m_description = PQgetvalue(result, i, 4);
ai.m_sequence = strtoul(PQgetvalue(result, i, 5), 0, 10);
ai.m_language = strtoul(PQgetvalue(result, i, 6), 0, 10);
ai.m_curPopulation = v_count_age_population(PQgetvalue(result, i, 1));
ai.m_population = v_count_age_owners(strtoul(PQgetvalue(result, i, 0), 0 , 10));
ages.push_back(ai);
}
PQclear(result);
return true;
}
示例6: find_a_friendly_neighborhood_for_our_new_visitor
static std::tuple<uint32_t, uint32_t>
find_a_friendly_neighborhood_for_our_new_visitor()
{
PGresult* result = PQexec(s_postgres,
"SELECT idx FROM vault.\"Nodes\" WHERE \"String64_2\"="
" 'Neighborhood' AND \"String64_4\" = '" HOOD_USER_NAME "'"
" ORDER BY \"Int32_1\"");
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return std::make_tuple<uint32_t, uint32_t>(0, 0);
}
uint32_t theHoodInfo = 0;
for (int i = 0; i < PQntuples(result); ++i) {
uint32_t ageInfoId = strtoul(PQgetvalue(result, i, 0), 0, 10);
uint32_t owners = v_count_age_owners(ageInfoId);
if (owners < HOOD_POPULATION_THRESHOLD) {
theHoodInfo = ageInfoId;
break;
}
}
PQclear(result);
// Need new hood?
if (theHoodInfo == 0) {
AuthServer_AgeInfo age;
age.m_ageId = gen_uuid();
age.m_filename = "Neighborhood";
age.m_instName = HOOD_INSTANCE_NAME;
age.m_userName = HOOD_USER_NAME;
age.m_description = HOOD_USER_NAME " " HOOD_INSTANCE_NAME;
age.m_seqNumber = -1; // Auto-generate
theHoodInfo = std::get<1>(v_create_age(age, e_AgePublic));
}
// It's important to BCast new hood members, so we'll return the ageOwners folder
PostgresStrings<2> parms;
parms.set(0, theHoodInfo);
parms.set(1, DS::Vault::e_AgeOwnersFolder);
result = PQexecParams(s_postgres, "SELECT idx FROM vault.find_folder($1, $2);",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) == PGRES_TUPLES_OK) {
uint32_t ownersFolder = strtoul(PQgetvalue(result, 0, 0), 0, 10);
PQclear(result);
return std::make_tuple(theHoodInfo, ownersFolder);
} else {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return std::make_tuple(0, 0);
}
}
示例7: dm_vault_init
bool dm_vault_init()
{
PostgresStrings<1> sparm;
sparm.set(0, DS::Vault::e_NodeSystem);
PGresult* result = PQexecParams(s_postgres,
"SELECT \"idx\" FROM vault.\"Nodes\""
" WHERE \"NodeType\"=$1",
1, 0, sparm.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
int count = PQntuples(result);
if (count == 0) {
PQclear(result);
fputs("[Vault] Initializing empty DirtSand vault\n", stderr);
// Create system and global inbox nodes
DS::Vault::Node node;
node.set_NodeType(DS::Vault::e_NodeSystem);
s_systemNode = v_create_node(node);
if (s_systemNode == 0)
return false;
node.set_NodeType(DS::Vault::e_NodeFolder);
node.set_Int32_1(DS::Vault::e_GlobalInboxFolder);
uint32_t globalInbox = v_create_node(node);
if (globalInbox == 0)
return false;
if (!v_ref_node(s_systemNode, globalInbox, 0))
return false;
std::list<AuthServer_AgeInfo> ages = configure_static_ages();
for (auto iter = ages.begin(); iter != ages.end(); ++iter) {
if (std::get<0>(v_create_age(*iter, e_AgePublic)) == 0)
return false;
}
} else {
DS_DASSERT(count == 1);
s_systemNode = strtoul(PQgetvalue(result, 0, 0), 0, 10);
PQclear(result);
}
return true;
}
示例8: find_public_age_1
static uint32_t find_public_age_1(const DS::String& filename)
{
PGresult* result;
{
PostgresStrings<1> parm;
parm.set(0, filename);
result = PQexecParams(s_postgres,
"SELECT \"AgeUuid\" FROM game.\"PublicAges\""
" WHERE \"AgeFilename\"=$1 AND \"SeqNumber\"=0",
1, 0, parm.m_values, 0, 0, 0);
}
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return 0;
}
DS_DASSERT(PQntuples(result) == 1);
DS::Uuid ageId(PQgetvalue(result, 0, 0));
PQclear(result);
{
PostgresStrings<2> parms;
parms.set(0, DS::Vault::e_NodeAgeInfo);
parms.set(1, ageId.toString());
result = PQexecParams(s_postgres,
"SELECT idx FROM vault.\"Nodes\""
" WHERE \"NodeType\"=$1 AND \"Uuid_1\"=$2",
2, 0, parms.m_values, 0, 0, 0);
}
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return 0;
}
if (PQntuples(result) == 0) {
// Public age not found
PQclear(result);
return 0;
}
DS_DASSERT(PQntuples(result) == 1);
uint32_t ageInfoNode = strtoul(PQgetvalue(result, 0, 0), 0, 10);
PQclear(result);
return ageInfoNode;
}
示例9: dm_game_shutdown
void dm_game_shutdown(GameHost_Private* host)
{
{
std::lock_guard<std::mutex> clientGuard(host->m_clientMutex);
for (auto client_iter = host->m_clients.begin(); client_iter != host->m_clients.end(); ++client_iter)
DS::CloseSock(client_iter->second->m_sock);
}
for (auto clone_iter = host->m_clones.begin(); clone_iter != host->m_clones.end(); ++clone_iter)
clone_iter->second->unref();
host->m_clones.clear();
bool complete = false;
for (int i=0; i<50 && !complete; ++i) {
host->m_clientMutex.lock();
size_t alive = host->m_clients.size();
host->m_clientMutex.unlock();
if (alive == 0)
complete = true;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (!complete)
fputs("[Game] Clients didn't die after 5 seconds!\n", stderr);
s_gameHostMutex.lock();
hostmap_t::iterator host_iter = s_gameHosts.begin();
while (host_iter != s_gameHosts.end()) {
if (host_iter->second == host)
host_iter = s_gameHosts.erase(host_iter);
else
++host_iter;
}
s_gameHostMutex.unlock();
if (host->m_temp) {
PostgresStrings<1> params;
params.set(0, host->m_serverIdx);
PQexecParams(host->m_postgres,
"DELETE FROM game.\"Servers\" "
" WHERE \"idx\"=$1;",
1, 0, params.m_values, 0, 0, 0);
}
PQfinish(host->m_postgres);
delete host;
}
示例10: v_unref_node
bool v_unref_node(uint32_t parentIdx, uint32_t childIdx)
{
PostgresStrings<2> parms;
parms.set(0, parentIdx);
parms.set(1, childIdx);
PGresult* result = PQexecParams(s_postgres,
"DELETE FROM vault.\"NodeRefs\""
" WHERE \"ParentIdx\"=$1 AND \"ChildIdx\"=$2",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
fprintf(stderr, "%s:%d:\n Postgres DELETE error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
PQclear(result);
return true;
}
示例11: find_public_age_1
static uint32_t find_public_age_1(const DS::String& filename)
{
PostgresStrings<1> parm;
parm.set(0, filename);
PGresult* result = PQexecParams(s_postgres, "SELECT idx FROM vault.\"Nodes\""
" WHERE \"Int32_2\" = 1 AND \"String64_2\"=$1",
1, 0, parm.m_values, 0, 0, 0);
uint32_t ageInfoId = 0;
if (PQresultStatus(result) == PGRES_TUPLES_OK) {
DS_DASSERT(PQntuples(result) == 1);
ageInfoId = strtoul(PQgetvalue(result, 0, 0), 0, 10);
} else {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
}
PQclear(result);
return ageInfoId;
}
示例12: v_count_age_population
uint32_t v_count_age_population(const char* uuid)
{
PostgresStrings<2> parms;
parms.set(0, DS::Vault::e_NodePlayerInfo);
parms.set(1, uuid);
PGresult* result = PQexecParams(s_postgres,
"SELECT COUNT(*) FROM vault.\"Nodes\" WHERE \"NodeType\"=$1 AND"
" \"Int32_1\"=1 AND \"Uuid_1\"=$2",
2, 0, parms.m_values, 0, 0, 0);
uint32_t population = 0;
if (PQresultStatus(result) == PGRES_TUPLES_OK) {
population = strtoul(PQgetvalue(result, 0, 0), 0, 10);
} else {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
}
PQclear(result);
return population;
}
示例13: v_ref_node
bool v_ref_node(uint32_t parentIdx, uint32_t childIdx, uint32_t ownerIdx)
{
PostgresStrings<3> parms;
parms.set(0, parentIdx);
parms.set(1, childIdx);
parms.set(2, ownerIdx);
PGresult* result = PQexecParams(s_postgres,
"INSERT INTO vault.\"NodeRefs\""
" (\"ParentIdx\", \"ChildIdx\", \"OwnerIdx\")"
" VALUES ($1, $2, $3)",
3, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
fprintf(stderr, "%s:%d:\n Postgres INSERT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
PQclear(result);
return true;
}
示例14: dm_save_sdl_state
void dm_save_sdl_state(GameHost_Private* host, const DS::String& descriptor,
const MOUL::Uoid& object, const SDL::State& state)
{
check_postgres(host);
DS::Blob sdlBlob = state.toBlob();
PostgresStrings<4> parms;
host->m_buffer.truncate();
object.write(&host->m_buffer);
parms.set(0, host->m_serverIdx);
parms.set(1, descriptor);
parms.set(2, DS::Base64Encode(host->m_buffer.buffer(), host->m_buffer.size()));
parms.set(3, DS::Base64Encode(sdlBlob.buffer(), sdlBlob.size()));
PGresult* result = PQexecParams(host->m_postgres,
"SELECT idx FROM game.\"AgeStates\""
" WHERE \"ServerIdx\"=$1 AND \"Descriptor\"=$2 AND \"ObjectKey\"=$3",
3, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(host->m_postgres));
PQclear(result);
return;
}
if (PQntuples(result) == 0) {
PQclear(result);
result = PQexecParams(host->m_postgres,
"INSERT INTO game.\"AgeStates\""
" (\"ServerIdx\", \"Descriptor\", \"ObjectKey\", \"SdlBlob\")"
" VALUES ($1, $2, $3, $4)",
4, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
fprintf(stderr, "%s:%d:\n Postgres INSERT error: %s\n",
__FILE__, __LINE__, PQerrorMessage(host->m_postgres));
PQclear(result);
return;
}
PQclear(result);
} else {
DS_DASSERT(PQntuples(result) == 1);
parms.set(0, DS::String(PQgetvalue(result, 0, 0)));
parms.set(1, parms.m_strings[3]); // SDL blob
PQclear(result);
result = PQexecParams(host->m_postgres,
"UPDATE game.\"AgeStates\""
" SET \"SdlBlob\"=$2 WHERE idx=$1",
2, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
fprintf(stderr, "%s:%d:\n Postgres UPDATE error: %s\n",
__FILE__, __LINE__, PQerrorMessage(host->m_postgres));
PQclear(result);
return;
}
PQclear(result);
}
}
示例15: v_update_node
bool v_update_node(const DS::Vault::Node& node)
{
/* This should be plenty to store everything we need without a bunch
* of dynamic reallocations
*/
PostgresStrings<32> parms;
char fieldbuf[1024];
size_t parmcount = 1;
char* fieldp = fieldbuf;
#define SET_FIELD(name, value) \
{ \
parms.set(parmcount++, value); \
fieldp += sprintf(fieldp, "\"" #name "\"=$%Zu,", parmcount); \
}
int now = time(0);
SET_FIELD(ModifyTime, now);
if (node.has_CreateAgeName())
SET_FIELD(CreateAgeName, node.m_CreateAgeName);
if (node.has_CreateAgeUuid())
SET_FIELD(CreateAgeUuid, node.m_CreateAgeUuid.toString());
if (node.has_CreatorUuid())
SET_FIELD(CreatorUuid, node.m_CreatorUuid.toString());
if (node.has_CreatorIdx())
SET_FIELD(CreatorIdx, node.m_CreatorIdx);
if (node.has_NodeType())
SET_FIELD(NodeType, node.m_NodeType);
if (node.has_Int32_1())
SET_FIELD(Int32_1, node.m_Int32_1);
if (node.has_Int32_2())
SET_FIELD(Int32_2, node.m_Int32_2);
if (node.has_Int32_3())
SET_FIELD(Int32_3, node.m_Int32_3);
if (node.has_Int32_4())
SET_FIELD(Int32_4, node.m_Int32_4);
if (node.has_Uint32_1())
SET_FIELD(Uint32_1, node.m_Uint32_1);
if (node.has_Uint32_2())
SET_FIELD(Uint32_2, node.m_Uint32_2);
if (node.has_Uint32_3())
SET_FIELD(Uint32_3, node.m_Uint32_3);
if (node.has_Uint32_4())
SET_FIELD(Uint32_4, node.m_Uint32_4);
if (node.has_Uuid_1())
SET_FIELD(Uuid_1, node.m_Uuid_1.toString());
if (node.has_Uuid_2())
SET_FIELD(Uuid_2, node.m_Uuid_2.toString());
if (node.has_Uuid_3())
SET_FIELD(Uuid_3, node.m_Uuid_3.toString());
if (node.has_Uuid_4())
SET_FIELD(Uuid_4, node.m_Uuid_4.toString());
if (node.has_String64_1())
SET_FIELD(String64_1, node.m_String64_1);
if (node.has_String64_2())
SET_FIELD(String64_2, node.m_String64_2);
if (node.has_String64_3())
SET_FIELD(String64_3, node.m_String64_3);
if (node.has_String64_4())
SET_FIELD(String64_4, node.m_String64_4);
if (node.has_String64_5())
SET_FIELD(String64_5, node.m_String64_5);
if (node.has_String64_6())
SET_FIELD(String64_6, node.m_String64_6);
if (node.has_IString64_1())
SET_FIELD(IString64_1, node.m_IString64_1);
if (node.has_IString64_2())
SET_FIELD(IString64_2, node.m_IString64_2);
if (node.has_Text_1())
SET_FIELD(Text_1, node.m_Text_1);
if (node.has_Text_2())
SET_FIELD(Text_2, node.m_Text_2);
if (node.has_Blob_1())
SET_FIELD(Blob_1, DS::Base64Encode(node.m_Blob_1.buffer(), node.m_Blob_1.size()));
if (node.has_Blob_2())
SET_FIELD(Blob_2, DS::Base64Encode(node.m_Blob_2.buffer(), node.m_Blob_2.size()));
#undef SET_FIELD
DS_DASSERT(fieldp - fieldbuf < 1024);
*(fieldp - 1) = 0; // Get rid of the last comma
DS::String queryStr = "UPDATE vault.\"Nodes\"\n SET ";
queryStr += fieldbuf;
queryStr += "\n WHERE idx=$1";
parms.set(0, node.m_NodeIdx);
check_postgres();
PGresult* result = PQexecParams(s_postgres, queryStr.c_str(),
parmcount, 0, parms.m_values, 0, 0, 0);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
fprintf(stderr, "%s:%d:\n Postgres UPDATE error: %s\n",
__FILE__, __LINE__, PQerrorMessage(s_postgres));
PQclear(result);
return false;
}
PQclear(result);
return true;
}