bool Database::deleteHouse(Int64 buildingID, Int64 buildingUID) { Poco::Data::Statement stmt((*activeSession)); stmt << "delete from `buildings` where `unique_id` = ? and `building_id` = ? and `instance_id` = ?", use(buildingUID), use(buildingID), use(serverID), now; return true; }
static void stmtlist() { stmt(); morestmts(); /* YOUR CODE GOES HERE */ }
TEST(DynTypedNode, StmtDump) { DumpVerifier Verifier; Verifier.expectSubstring("CompoundStmt"); EXPECT_TRUE(Verifier.match("void f() {}", stmt())); }
// read a linear shapefile and create a vector point layer with the end points of line features void layer_line2point(){ CV::Util::Spatialite::Connection cnn; cnn.open(TEST_GEO_DB); std::cout << "DB open" << std::endl; if ( cnn.check_metadata() == CV::Util::Spatialite::Connection::NO_SPATIAL_METADATA ){ std::cout << "DB with no spatial metadata" << std::endl; return; } std::cout << "DB is spatial initialized " << std::endl; try { cnn.remove_layer("AVOLOP_PT"); } catch(...){} //create output layer cnn.begin_transaction(); cnn.execute_immediate("Create table AVOLOP_PT ( PK_UID INTEGER PRIMARY KEY AUTOINCREMENT, id double )"); cnn.execute_immediate("select AddGeometryColumn('AVOLOP_PT', 'geom', 32632, 'POINT' )"); cnn.commit_transaction(); CV::Util::Spatialite::Statement stmt(cnn, "select ID, HEIGHT, AsBinary(geom) from AVOLOP"); CV::Util::Spatialite::Recordset rs = stmt.recordset(); CV::Util::Spatialite::Statement stmt_out( cnn, "insert into AVOLOP_PT (id, geom) values (:id, ST_GeomFromWKB(:geom, 32632) )"); //CV::Util::Spatialite::Statement stmt_out( cnn, "insert into AVOLOP_PT (id, geom) values (:id, ST_GeomFromTEXT('POINTZ(648322.57782173 4736657.061840324 2500.2)', 32632) )"); while( !rs.eof() ){ int id = rs[0].toInt(); double height = rs[1].toDouble(); std::vector<unsigned char> gg = rs[2]; //rs[2].toBlob(gg); OGRPoint firstlast[2]; //return first and last point of the line string line2end_points(gg, firstlast); // firstlast[0].setZ(height); // firstlast[1].setZ(height); for( int i=0; i<2; i++){ std::vector<unsigned char> buffin; char *buffout=NULL; int size_out = 0, size_in = firstlast[i].WkbSize(); buffin.resize(size_in); firstlast[i].exportToWkb(wkbNDR, &buffin[0]); firstlast[i].exportToWkt(&buffout); std::cout << std::string(buffout) << std::endl; OGRFree(buffout); /* gaiaGeomCollPtr geo = gaiaFromWkb(&buffin[0], size_in); geo->Srid = 32632; geo->DimensionModel = GAIA_XY_Z; geo->DeclaredType = GAIA_POINTZ; // debug in wkt gaiaOutBuffer wkt; gaiaOutBufferInitialize(&wkt); gaiaToEWKT(&wkt, geo); std::cout << std::string(wkt.Buffer, wkt.BufferSize) << std::endl; gaiaOutBufferReset(&wkt); gaiaToSpatiaLiteBlobWkb(geo, &buffout, &size_out); std::vector<unsigned char> vtmp; vtmp.resize(size_out); memcpy(&vtmp[0], buffout, size_out); gaiaFree(buffout); gaiaFreeGeomColl(geo); */ stmt_out[1] = id; stmt_out[2].fromBlob(buffin); stmt_out.execute(); stmt_out.reset(); } rs.next(); } }
int dodo() {int jdest; int jtemp; nlabel++; jdest=nlabel; prlabel(jdest); stmt(); expect(T_WHILE); pexpr(); nlabel++; jtemp=nlabel; prnum(jtemp); prjump(jdest); prlabel(jtemp); }
bool IOLoginData::savePlayer(Player* player) { if (player->getHealth() <= 0) { player->changeHealth(1); } Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID(); DBResult* result = db->storeQuery(query.str()); if (!result) { return false; } if (result->getDataInt("save") == 0) { db->freeResult(result); query.str(""); query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID(); return db->executeQuery(query.str()); } db->freeResult(result); //serialize conditions PropWriteStream propWriteStream; for (ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it) { Condition* condition = *it; if (condition->isPersistent()) { if (!condition->serialize(propWriteStream)) { return false; } propWriteStream.ADD_UCHAR(CONDITIONATTR_END); } } uint32_t conditionsSize = 0; const char* conditions = propWriteStream.getStream(conditionsSize); //First, an UPDATE query to write the player itself query.str(""); query << "UPDATE `players` SET "; query << "`level` = " << player->level << ", "; query << "`group_id` = " << player->groupId << ", "; query << "`vocation` = " << (int32_t)player->getVocationId() << ", "; query << "`health` = " << player->health << ", "; query << "`healthmax` = " << player->healthMax << ", "; query << "`experience` = " << player->experience << ", "; query << "`lookbody` = " << (int32_t)player->defaultOutfit.lookBody << ", "; query << "`lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet << ", "; query << "`lookhead` = " << (int32_t)player->defaultOutfit.lookHead << ", "; query << "`looklegs` = " << (int32_t)player->defaultOutfit.lookLegs << ", "; query << "`looktype` = " << (int32_t)player->defaultOutfit.lookType << ", "; query << "`lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons << ", "; query << "`maglevel` = " << player->magLevel << ", "; query << "`mana` = " << player->mana << ", "; query << "`manamax` = " << player->manaMax << ", "; query << "`manaspent` = " << player->manaSpent << ", "; query << "`soul` = " << player->soul << ", "; query << "`town_id` = " << player->town << ", "; const Position& loginPosition = player->getLoginPosition(); query << "`posx` = " << loginPosition.x << ", "; query << "`posy` = " << loginPosition.y << ", "; query << "`posz` = " << loginPosition.z << ", "; query << "`cap` = " << player->getCapacity() << ", "; query << "`sex` = " << player->sex << ", "; if (player->lastLoginSaved != 0) { query << "`lastlogin` = " << player->lastLoginSaved << ", "; } if (player->lastIP != 0) { query << "`lastip` = " << player->lastIP << ", "; } query << "`conditions` = " << db->escapeBlob(conditions, conditionsSize) << ", "; if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) { int32_t skullTime = 0; if (player->skullTicks > 0) { skullTime = time(NULL) + player->skullTicks / 1000; } query << "`skulltime` = " << skullTime << ", "; int32_t skull = 0; if (player->skull == SKULL_RED) { skull = SKULL_RED; } else if (player->skull == SKULL_BLACK) { skull = SKULL_BLACK; } query << "`skull` = " << skull << ", "; } query << "`lastlogout` = " << player->getLastLogout() << ", "; query << "`balance` = " << player->bankBalance << ", "; query << "`offlinetraining_time` = " << player->getOfflineTrainingTime() / 1000 << ", "; query << "`offlinetraining_skill` = " << player->getOfflineTrainingSkill() << ", "; query << "`stamina` = " << player->getStaminaMinutes() << ", "; if (!player->isOffline()) { query << "`onlinetime` = `onlinetime` + " << (time(NULL) - player->lastLoginSaved) << ", "; } query << "`blessings` = " << player->blessings; query << " WHERE `id` = " << player->getGUID(); DBTransaction transaction; if (!transaction.begin()) { return false; } if (!db->executeQuery(query.str())) { return false; } // skills for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; i++) { query.str(""); query << "UPDATE `player_skills` SET `value` = " << player->skills[i][SKILL_LEVEL] << ", `count` = " << player->skills[i][SKILL_TRIES] << " WHERE `player_id` = " << player->getGUID() << " AND `skillid` = " << i; if (!db->executeQuery(query.str())) { return false; } } // learned spells query.str(""); query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } query.str(""); DBInsert stmt(db); stmt.setQuery("INSERT INTO `player_spells` (`player_id`, `name` ) VALUES "); for (LearnedInstantSpellList::const_iterator it = player->learnedInstantSpellList.begin(); it != player->learnedInstantSpellList.end(); ++it) { query << player->getGUID() << "," << db->escapeString(*it); if (!stmt.addRow(query)) { return false; } } if (!stmt.execute()) { return false; } //item saving query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } stmt.setQuery("INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); ItemBlockList itemList; for (int32_t slotId = 1; slotId <= 10; ++slotId) { Item* item = player->inventory[slotId]; if (item) { itemList.push_back(itemBlock(slotId, item)); } } if (!saveItems(player, itemList, stmt)) { return false; } if (player->depotChange) { //save depot items query.str(""); query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } stmt.setQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); itemList.clear(); for (DepotMap::iterator it = player->depotChests.begin(); it != player->depotChests.end() ; ++it) { DepotChest* depotChest = it->second; for (ItemDeque::const_iterator iit = depotChest->getItems(), end = depotChest->getEnd(); iit != end; ++iit) { itemList.push_back(itemBlock(it->first, *iit)); } } if (!saveItems(player, itemList, stmt)) { return false; } } //save inbox items query.str(""); query << "DELETE FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } stmt.setQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); itemList.clear(); for (ItemDeque::const_iterator it = player->getInbox()->getItems(), end = player->getInbox()->getEnd(); it != end; ++it) { itemList.push_back(itemBlock(0, *it)); } if (!saveItems(player, itemList, stmt)) { return false; } query.str(""); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } query.str(""); stmt.setQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES "); player->genReservedStorageRange(); for (StorageMap::const_iterator cit = player->getStorageIteratorBegin(), end = player->getStorageIteratorEnd(); cit != end; ++cit) { query << player->getGUID() << "," << cit->first << "," << cit->second; if (!stmt.addRow(query)) { return false; } } if (!stmt.execute()) { return false; } //End the transaction return transaction.commit(); }
void Repo::exec(const std::string& sQuery) { RepoStmt stmt(*this); stmt.prepare(sQuery); RepoQuery query(stmt); query.exec(); }
bool Database::kickLog(string name, string guid, string kick) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `battleye` (`name`, `guid`, `message`, `instance`) VALUES (?,?,?,?)", use(name), use(guid), use(kick), use(serverID), now; return true; };
bool Database::adminLog(string playerID, string playerName, string action) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `admin_log` (`player_id`, `name`, `action`, `instance`) VALUES (?,?,?,?)", use(playerID), use(playerName), use(action), use(serverID), now; return true; };
bool Database::storageLog(string playerID, string playerName, string deployableID, string deployableName, string ownerID) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `storage_log` (`player_id`, `player_name`, `deployable_id`, `deployable_name`, `owner_id`, `instance`) VALUES (?,?,?,?,?,?)", use(playerID), use(playerName), use(deployableID), use(deployableName), use(ownerID), use(serverID), now; return true; };
bool Database::hackLog(string playerID, string playerName, string reason) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `bans_pid` (`player_id`, `name`, `reason`, `instance`) VALUES (?,?,?,?)", use(playerID), use(playerName), use(reason), use(serverID), now; return true; };
bool Database::killLog(string playerID, string playerName, string killerID, string killerName, int distance, string weapon) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `kill_log` (`player_id`, `player_name`, `killer_id`, `killer_name`, `distance`, `weapon`, `instance`) VALUES (?,?,?,?,?,?,?)", use(playerID), use(playerName), use(killerID), use(killerName), use(distance), use(weapon), use(serverID), now; return true; };
bool Database::combatLog(string playerID, string playerName, int characterID) { Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `combat_log` (`player_id`, `player_name`, `character_id`, `instance`) VALUES (?,?,?,?)", use(playerID), use(playerName), use(characterID), use(serverID), now; return true; };
bool Database::timestampHouse(Int64 buildingID) { Poco::Data::Statement stmt((*activeSession)); stmt << "UPDATE `buildings` SET `lastupdated` = now() WHERE `unique_id` = ? and `instance_id` = ?", use(buildingID), use(serverID), now; return true; }
bool IOMapSerialize::saveItems(Database* db, uint32_t& tileId, uint32_t houseId, const Tile* tile) { int32_t thingCount = tile->getThingCount(); if(!thingCount) return true; Item* item = NULL; int32_t runningId = 0, parentId = 0; ContainerStackList containerStackList; bool stored = false; DBInsert stmt(db); stmt.setQuery("INSERT INTO `tile_items` (`tile_id`, `world_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES "); DBQuery query; for(int32_t i = 0; i < thingCount; ++i) { if(!(item = tile->__getThing(i)->getItem()) || (!item->isMovable() && !item->forceSerialize())) continue; if(!stored) { Position tilePosition = tile->getPosition(); query << "INSERT INTO `tiles` (`id`, `world_id`, `house_id`, `x`, `y`, `z`) VALUES (" << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << houseId << ", " << tilePosition.x << ", " << tilePosition.y << ", " << tilePosition.z << ")"; if(!db->query(query.str())) return false; stored = true; query.str(""); } PropWriteStream propWriteStream; item->serializeAttr(propWriteStream); uint32_t attributesSize = 0; const char* attributes = propWriteStream.getStream(attributesSize); query << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << ++runningId << ", " << parentId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize); if(!stmt.addRow(query.str())) return false; query.str(""); if(item->getContainer()) containerStackList.push_back(std::make_pair(item->getContainer(), runningId)); } Container* container = NULL; for(ContainerStackList::iterator cit = containerStackList.begin(); cit != containerStackList.end(); ++cit) { container = cit->first; parentId = cit->second; for(ItemDeque::const_iterator it = container->getItems(); it != container->getEnd(); ++it) { if(!(item = *it)) continue; PropWriteStream propWriteStream; item->serializeAttr(propWriteStream); uint32_t attributesSize = 0; const char* attributes = propWriteStream.getStream(attributesSize); query << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << ++runningId << ", " << parentId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize); if(!stmt.addRow(query.str())) return false; query.str(""); if(item->getContainer()) containerStackList.push_back(std::make_pair(item->getContainer(), runningId)); } } if(stored) ++tileId; return stmt.execute(); }
void Database::shutdownCleanup() { //Cleanup Invalid Storage Objects Poco::Data::Statement stmt((*activeSession)); stmt << "DELETE FROM `instance_deployable` WHERE `unique_id` = '0' AND `instance_id` = ?", use(serverID), now; }
void cMojangAPI::SaveCachesToDisk(void) { try { // Open up the SQLite DB: SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); // Remove all entries: db.exec("DELETE FROM PlayerNameToUUID"); db.exec("DELETE FROM UUIDToProfile"); // Save all cache entries - m_PlayerNameToUUID: Int64 LimitDateTime = time(nullptr) - MAX_AGE; { SQLite::Statement stmt(db, "INSERT INTO PlayerNameToUUID(PlayerName, UUID, DateTime) VALUES (?, ?, ?)"); cCSLock Lock(m_CSNameToUUID); for (auto & NameToUUID : m_NameToUUID) { auto & Profile = NameToUUID.second; if (Profile.m_DateTime < LimitDateTime) { // This item is too old, do not save continue; } stmt.bind(1, Profile.m_PlayerName); stmt.bind(2, Profile.m_UUID.ToShortString()); stmt.bind(3, Profile.m_DateTime); stmt.exec(); stmt.reset(); } } // Save all cache entries - m_UUIDToProfile: { SQLite::Statement stmt(db, "INSERT INTO UUIDToProfile(UUID, PlayerName, Textures, TexturesSignature, DateTime) VALUES (?, ?, ?, ?, ?)"); cCSLock Lock(m_CSUUIDToProfile); for (auto & UUIDToProfile : m_UUIDToProfile) { auto & Profile = UUIDToProfile.second; if (Profile.m_DateTime < LimitDateTime) { // This item is too old, do not save continue; } stmt.bind(1, Profile.m_UUID.ToShortString()); stmt.bind(2, Profile.m_PlayerName); stmt.bind(3, Profile.m_Textures); stmt.bind(4, Profile.m_TexturesSignature); stmt.bind(5, Profile.m_DateTime); stmt.exec(); stmt.reset(); } } } catch (const SQLite::Exception & ex) { LOGINFO("Saving MojangAPI cache failed: %s", ex.what()); } }
void Database::populateObjects(std::queue<Sqf::Parameters>& queue) { try { //Reset Ghosting Timer (Server Restart) for this instance Poco::Data::Statement ghostingStmt((*activeSession)); ghostingStmt << "UPDATE `survivor` SET `lastserver` = '0', `activeserver` = '0' WHERE `lastserver` = ? OR `activeserver` = ?", use(serverID), use(serverID); //Fetch Objects For This Instance Poco::Data::Statement stmt((*activeSession)); stmt << "select id.`unique_id`, d.`class_name`, id.`owner_id`, id.`player_id`, id.`worldspace`, id.`inventory`, id.`lock`, id.`building_id` from `instance_deployable` id inner join `deployable` d on id.`deployable_id` = d.`id` where id.`instance_id` = ? AND `deployable_id` IS NOT NULL", use(serverID); stmt.execute(); //Execute Ghosting Async ghostingStmt.executeAsync(); //Process Objects Data Set Poco::Data::RecordSet rs(stmt); if (rs.columnCount() >= 1) { bool more = rs.moveFirst(); while (more) { Sqf::Value worldSpace = Sqf::Parameters(); //[] Sqf::Value inventory = Sqf::Parameters(); //[] Sqf::Value parts = Sqf::Parameters(); //[] Sqf::Parameters objParams; objParams.push_back(string("OBJ")); string objectID = rs[0].convert<std::string>(); objParams.push_back(objectID); string classname = rs[1].convert<std::string>(); objParams.push_back(classname); string ownerID = rs[2].convert<std::string>(); objParams.push_back(ownerID); string playerID = rs[3].convert<std::string>(); objParams.push_back(playerID); try { string worldSpaceStr = rs[4].convert<std::string>(); worldSpace = lexical_cast<Sqf::Value>(worldSpaceStr); } catch (boost::bad_lexical_cast) { console->log("Invalid Worldspace for ObjectID: " + objectID); } objParams.push_back(worldSpace); try { string inventoryStr = rs[5].convert<std::string>(); inventory = lexical_cast<Sqf::Value>(inventoryStr); } catch (boost::bad_lexical_cast) { console->log("Invalid Inventory for ObjectID: " + objectID); } objParams.push_back(inventory); string lock = rs[6].convert<std::string>(); objParams.push_back(lock); string buildingID = rs[7].convert<std::string>(); objParams.push_back(buildingID); queue.push(objParams); more = rs.moveNext(); } } //Wait For Async Ghosting Timer Statement ghostingStmt.wait(); } catch (boost::bad_lexical_cast& ex) { console->log(ex.what()); } catch (boost::exception&) { console->log("unknown boost exception"); } catch (Data::MySQL::StatementException& ex) { console->log(ex.message()); } catch (Data::MySQL::TransactionException& ex) { console->log(ex.message()); } catch (std::exception& ex) { console->log(ex.what()); } }
void Repo::loadGlobalData(bool allowFailure /* = false */) { m_lsrp.load(); if (!RuntimeOption::RepoAuthoritative) return; std::vector<std::string> failures; /* * This should probably just go to the Local repo always, except * that our unit test suite is currently running RepoAuthoritative * tests with the compiled repo as the Central repo. */ for (int repoId = RepoIdCount - 1; repoId >= 0; --repoId) { if (repoName(repoId).empty()) { // The repo wasn't loadable continue; } try { RepoStmt stmt(*this); const auto& tbl = table(repoId, "GlobalData"); stmt.prepare( folly::format( "SELECT count(*), data from {};", tbl ).str() ); RepoTxn txn(*this); RepoTxnQuery query(txn, stmt); query.step(); if (!query.row()) { throw RepoExc("Can't find table %s", tbl.c_str()); }; int val; query.getInt(0, val); if (val == 0) { throw RepoExc("No rows in %s. Did you forget to compile that file with " "this HHVM version?", tbl.c_str()); }; BlobDecoder decoder = query.getBlob(1); decoder(s_globalData); txn.commit(); } catch (RepoExc& e) { failures.push_back(repoName(repoId) + ": " + e.msg()); continue; } return; } if (allowFailure) return; if (failures.empty()) { std::fprintf(stderr, "No repo was loadable. Check all the possible repo " "locations (Repo.Central.Path, HHVM_REPO_CENTRAL_PATH, and " "$HOME/.hhvm.hhbc) to make sure one of them is a valid " "sqlite3 HHVM repo built with this exact HHVM version.\n"); } else { // We should always have a global data section in RepoAuthoritative // mode, or the repo is messed up. std::fprintf(stderr, "Failed to load Repo::GlobalData:\n"); for (auto& f : failures) { std::fprintf(stderr, " %s\n", f.c_str()); } } assert(Process::IsInMainThread()); exit(1); }
void Database::populateVehicles(std::queue<Sqf::Parameters>& queue) { try { Poco::Data::Statement stmt((*activeSession)); stmt << "select `unique_id`, `classname`, `worldspace`, `inventory`, `parts`, `fuel`, `damage` from `instance_vehicle` where `instance_id` = ?", use(serverID), now; Poco::Data::RecordSet rs(stmt); if (rs.columnCount() >= 1) { bool more = rs.moveFirst(); while (more) { Sqf::Value worldSpace = Sqf::Parameters(); //[] Sqf::Value inventory = Sqf::Parameters(); //[] Sqf::Value parts = Sqf::Parameters(); //[] Sqf::Parameters objParams; objParams.push_back(string("VEH")); string uniqueID = rs[0].convert<std::string>(); objParams.push_back(uniqueID); string classname = rs[1].convert<std::string>(); objParams.push_back(classname); try { string worldSpaceStr = rs[2].convert<std::string>(); worldSpace = lexical_cast<Sqf::Value>(worldSpaceStr); } catch (boost::bad_lexical_cast) { console->log("Invalid Worldspace for ObjectID: " + uniqueID); } objParams.push_back(worldSpace); try { string inventoryStr = rs[3].convert<std::string>(); inventory = lexical_cast<Sqf::Value>(inventoryStr); } catch (boost::bad_lexical_cast) { console->log("Invalid Inventory for ObjectID: " + uniqueID); } objParams.push_back(inventory); try { string partsStr = rs[4].convert<std::string>(); parts = lexical_cast<Sqf::Value>(partsStr); } catch (boost::bad_lexical_cast) { console->log("Invalid Parts for ObjectID: " + uniqueID); } objParams.push_back(parts); double fuel = rs[5].convert<double>(); objParams.push_back(fuel); double damage = rs[6].convert<double>(); objParams.push_back(damage); queue.push(objParams); more = rs.moveNext(); } } } catch (boost::bad_lexical_cast& ex) { console->log(ex.what()); } catch (boost::exception&) { console->log("unknown boost exception"); } catch (Data::MySQL::StatementException& ex) { console->log(ex.message()); } catch (Data::MySQL::TransactionException& ex) { console->log(ex.message()); } catch (std::exception& ex) { console->log(ex.what()); } }
NodeInt stmt() { switch (CurrToken) { case INT32:{ mutch(INT32); Token tokL = mutch(IDENTIFIER); int idNum = Lookup(lexeme, 1, INT32); NodeInt nodeL = AddLeaf(tokL, idNum); if(CurrToken == MOV_OP){ Token tok = mutch(MOV_OP); NodeInt nodeR = boool(); mutch(COMM_POINT); return AddNode(tok, nodeL,0,nodeR); } mutch(COMM_POINT); NodeInt nodeR = AddLeaf(NUMBER, 0); return AddNode(MOV_OP, nodeL, 0,nodeR); break; } case INT16:{ mutch(INT16); Token tokL = mutch(IDENTIFIER); int idNum = Lookup(lexeme, 1, INT16); NodeInt nodeL = AddLeaf(tokL, idNum); if(CurrToken == MOV_OP){ Token tok = mutch(MOV_OP); NodeInt nodeR = boool(); mutch(COMM_POINT); return AddNode(tok, nodeL,0,nodeR); } mutch(COMM_POINT); NodeInt nodeR = AddLeaf(NUMBER, 0); return AddNode(MOV_OP, nodeL, 0,nodeR); break; } case DO:{ mutch(DO); NodeInt nodeL = stmt(); mutch(WHILE); mutch(LEFT_BRECKET); NodeInt nodeR = boool(); mutch(RIGHT_BRECKET); mutch(COMM_POINT); return AddNode(DO, nodeL, 0,nodeR); break; } case IF:{ Token tok = mutch(IF); mutch(LEFT_BRECKET); NodeInt nodeL = boool(); mutch(RIGHT_BRECKET); NodeInt nodeR = stmt(); NodeInt nodeM = 0; if(CurrToken == ELSE){ tok = mutch(ELSE); nodeM = stmt(); } return AddNode(tok, nodeL, nodeM, nodeR); break; } case LEFT_FIG_BRECKET:{ mutch(LEFT_FIG_BRECKET); NodeInt node = stmts(); mutch(RIGHT_FIG_BRECKET); return AddNode(STMT, node, 0, 0); break; } case IDENTIFIER:{ Token tok = mutch(IDENTIFIER); if(CurrToken == MOV_OP){ int idNum = Lookup(lexeme,0,0); if (idNum < 0){ printf("Syntax error:В строке %d использована не объявленая переменная \n",line); return 0; } NodeInt idLeaf = AddLeaf(IDENTIFIER, idNum); tok = mutch(MOV_OP); NodeInt nodeR = boool(); mutch(COMM_POINT); return AddNode(tok, idLeaf, 0,nodeR); } if(CurrToken == LEFT_BRECKET){ int idNum = Lookup(lexeme,1,0); if (idNum < 0){ printf("Syntax error:В строке %d использована не объявленая переменная \n",line); return 0; } NodeInt idLeaf = AddLeaf(IDENTIFIER, idNum); mutch(LEFT_BRECKET); NodeInt nodeR =boool(); mutch(RIGHT_BRECKET); mutch(COMM_POINT); return AddNode(FUNCTION, idLeaf, 0, nodeR); } break; } case CONTINUE:{ return AddNode(CONTINUE, 0, 0, 0); } case BREAK:{ return AddNode(BREAK, 0, 0, 0); } default: printf("Syntaxes error\n"); return 0; break; } }
Sqf::Value Database::fetchCharacterInitial(string playerID, string playerName) { try { bool newPlayer = false; std::string guid = VAC::convertSteamIDtoBEGUID(playerID); //Make Sure Player Exists in the Database { Poco::Data::Statement stmt((*activeSession)); stmt << "select `name` from `profile` WHERE `unique_id` = ?", use(playerID), now; Poco::Data::RecordSet rs(stmt); if (rs.rowCount() > 0 && rs.columnCount() >= 1) { std::string dbName = rs[0].convert<std::string>(); if (playerName != dbName) { Poco::Data::Statement name_stmt((*activeSession)); name_stmt << "update `profile` set `name` = ? where `unique_id` = ?", use(playerName), use(playerID), now; }; } else { newPlayer = true; Poco::Data::Statement profile_stmt((*activeSession)); profile_stmt << "insert into `profile` (`unique_id`, `name`, `guid`) values (?, ?, ?)", use(playerID), use(playerName), use(guid), now; } } //Get Characters From Database Poco::Data::Statement character_stmt((*activeSession)); character_stmt << "select s.`id`, s.`lastserver`, s.`activeserver`, s.`inventory`, s.`backpack`, " "timestampdiff(minute, s.`start_time`, s.`last_updated`) as `SurvivalTime`, " "timestampdiff(minute, s.`last_updated`, NOW()) as `MinsLastUpdate`, " //"timestampdiff(minute, s.`last_drank`, NOW()) as `MinsLastDrank`, " "s.`dog` from `survivor` s join `instance` i on s.`world_id` = i.`world_id` and i.`id` = ? where s.`unique_id` = ? and s.`is_dead` = 0", use(serverID), use(playerID), now; Poco::Data::RecordSet rs(character_stmt); bool newChar = false; //not a new char int characterID = -1; //invalid charid int lastServer = 0; int activeServer = 0; Sqf::Value inventory = lexical_cast<Sqf::Value>("[]"); //empty inventory Sqf::Value backpack = lexical_cast<Sqf::Value>("[]"); //empty backpack Sqf::Value survival = lexical_cast<Sqf::Value>("[0,0,0]"); //0 mins alive, 0 mins since last ate, 0 mins since last drank Sqf::Value medical = lexical_cast<Sqf::Value>("[false,false,false,false,false,false,false,0,12000,[],[0,0],0]"); string model = ""; //empty models will be defaulted by scripts Sqf::Value dog = lexical_cast<Sqf::Value>("[]"); //dog class id, dog hunger, dog thirst if (rs.rowCount() > 0 && rs.columnCount() >= 1) { characterID = rs[0].convert<int>(); lastServer = rs[1].convert<int>(); activeServer = rs[2].convert<int>(); string inv = rs[3].convert<std::string>(); inventory = lexical_cast<Sqf::Value>(inv); string bpk = rs[4].convert<std::string>(); backpack = lexical_cast<Sqf::Value>(bpk); { Sqf::Parameters& survivalArr = boost::get<Sqf::Parameters>(survival); int i; i = rs[5].convert<int>(); survivalArr[0] = i; i = rs[6].convert<int>(); survivalArr[1] = i; } string dg = rs[7].convert<std::string>(); dog = lexical_cast<Sqf::Value>(dg); } else { newChar = true; //Insert New Char into DB Poco::Data::Statement stmt((*activeSession)); stmt << "insert into `survivor` (`unique_id`, `world_id`) select ?, i.`world_id` from `instance` i where i.`id` = ?", use(playerID), use(serverID), now; //Get The New Character's ID { Poco::Data::Statement stmt((*activeSession)); stmt << "select s.`id` from `survivor` s join `instance` i on s.world_id = i.world_id and i.id = ? where s.`unique_id` = ? and s.`is_dead` = 0", use(serverID), use(playerID), now; Poco::Data::RecordSet rs(stmt); if (rs.rowCount() > 0 && rs.columnCount() >= 1) { characterID = rs[0].convert<int>(); } else { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); return retVal; } } } //Always Push Back Full Login Details Sqf::Parameters retVal; retVal.push_back(string("PASS")); retVal.push_back(newChar); retVal.push_back(lexical_cast<string>(characterID)); retVal.push_back(inventory); retVal.push_back(survival); retVal.push_back(lastServer); retVal.push_back(activeServer); retVal.push_back(dog); retVal.push_back(guid); return retVal; } catch (Poco::Exception const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (boost::bad_lexical_cast const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (boost::bad_get const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (std::exception const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } }
int doif() {int jdest; int tst; pexpr(); nlabel++; jdest=nlabel; prnum(jdest); stmt(); if (istoken(T_ELSE)) { nlabel++; tst=nlabel; prjump(tst); prlabel(jdest); stmt(); prlabel(tst); } else prlabel(jdest); }
Sqf::Value Database::fetchCharacterDetails(int characterID) { try { Poco::Data::Statement stmt((*activeSession)); stmt << "select s.`worldspace`, s.`medical`, s.`zombie_kills`, s.`headshots`, s.`survivor_kills`, s.`state`, s.`class`, p.`ranger`, p.`outlaw`, p.`hunter`, p.`nomad`, p.`survivalist`, p.`engineer`, p.`undead`, p.`total_survivor_kills`, p.`clan` " << "from `survivor` s join `profile` p on s.`unique_id` = p.`unique_id` where s.`id` = ?", use(characterID), now; Sqf::Parameters retVal; Poco::Data::Statement updateInstance((*activeSession)); updateInstance << "update `survivor` set `lastserver` = ?, `activeserver` = ? where `id` = ?", use(serverID), use(serverID), use(characterID); updateInstance.executeAsync(); Poco::Data::RecordSet rs(stmt); if (rs.rowCount() > 0 && rs.columnCount() >= 1) { Sqf::Value worldSpace = Sqf::Parameters(); //empty worldspace Sqf::Value medical = Sqf::Parameters(); //script will fill this in if empty Sqf::Value stats = lexical_cast<Sqf::Value>("[0,0,0]"); //killsZ, headZ, killsH Sqf::Value currentState = Sqf::Parameters(); //empty state (aiming, etc) int myClass = 0; int ranger = 0; int outlaw = 0; int hunter = 0; int nomad = 0; int survivalist = 0; int engineer = 0; int undead = 0; int humanKills = 0; string clan = "0"; //Get Worldspace try { string ws = rs[0].convert<std::string>(); worldSpace = lexical_cast<Sqf::Value>(ws); } catch (boost::bad_lexical_cast) { console->log("Invalid Worldspace for Character: " + characterID); } //Get Medical try { string med = rs[1].convert<std::string>(); medical = lexical_cast<Sqf::Value>(med); } catch (boost::bad_lexical_cast) { console->log("Invalid Medical for Character: " + characterID); } //Get Stats try { Sqf::Parameters& statsArr = boost::get<Sqf::Parameters>(stats); int i; i = rs[2].convert<int>(); statsArr[0] = i; i = rs[3].convert<int>(); statsArr[1] = i; i = rs[4].convert<int>(); statsArr[2] = i; } catch (boost::bad_lexical_cast) { console->log("Invalid Stats for Character: " + characterID); } //Get Current State try { string state = rs[5].convert<std::string>(); currentState = lexical_cast<Sqf::Value>(state); } catch (boost::bad_lexical_cast) { console->log("Invalid State for Character: " + characterID); } myClass = rs[6].convert<int>(); ranger = rs[7].convert<int>(); outlaw = rs[8].convert<int>(); hunter = rs[9].convert<int>(); nomad = rs[10].convert<int>(); survivalist = rs[11].convert<int>(); engineer = rs[12].convert<int>(); undead = rs[13].convert<int>(); humanKills = rs[14].convert<int>(); clan = rs[15].convert<string>(); retVal.push_back(string("PASS")); retVal.push_back(medical); retVal.push_back(stats); retVal.push_back(currentState); retVal.push_back(worldSpace); retVal.push_back(myClass); retVal.push_back(ranger); retVal.push_back(outlaw); retVal.push_back(hunter); retVal.push_back(nomad); retVal.push_back(survivalist); retVal.push_back(engineer); retVal.push_back(undead); retVal.push_back(clan); //Wait for Async Update Player Model / Instance to finish updateInstance.wait(); } else { retVal.push_back(string("ERROR")); } return retVal; } catch (Poco::Exception const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (boost::bad_lexical_cast const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (boost::bad_get const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } catch (std::exception const& ex) { Sqf::Parameters retVal; retVal.push_back(string("ERROR")); console->log(ex.what()); return retVal; } };
int dowhile() {int jdest; int tst; nlabel++; jdest=nlabel; prlabel(jdest); pexpr(); nlabel++; tst=nlabel; prnum(tst); stmt(); prjump(jdest); prlabel(tst); }
bool Database::updateCharacter(int characterID, const FieldsType& fields) { map<string, string> sqlFields; for (auto it = fields.begin(); it != fields.end(); ++it) { const string& name = it->first; const Sqf::Value& val = it->second; //arrays if (name == "worldspace" || name == "inventory" || name == "backpack" || name == "medical" || name == "state" || name == "dog") sqlFields[name] = "'" + lexical_cast<string>(val)+"'"; //booleans else if (name == "just_ate" || name == "just_drank") { if (boost::get<bool>(val)) { string newName = "last_ate"; if (name == "just_drank") newName = "last_drank"; sqlFields[newName] = "CURRENT_TIMESTAMP"; } } //other stats else if (name == "zombie_kills" || name == "headshots" || name == "survival_time" || name == "survivor_kills" || name == "lastserver" || name == "class" || name == "ranger" || name == "outlaw" || name == "hunter" || name == "nomad" || name == "survivalist") { sqlFields[name] = "'" + lexical_cast<string>(val)+"'"; } //strings else if (name == "model") { sqlFields[name] = "'" + boost::get<string>(val) +"'"; } } if (sqlFields.size() > 0) { string setClause = ""; bool joinProfile = false; for (auto it = sqlFields.begin(); it != sqlFields.end();) { string fieldName = it->first; if (fieldName == "ranger" || fieldName == "outlaw" || fieldName == "hunter" || fieldName == "nomad" || fieldName == "survivalist") { joinProfile = true; setClause += "p.`" + fieldName + "` = " + it->second; } else { setClause += "s.`" + fieldName + "` = " + it->second; } ++it; if (it != sqlFields.end()) setClause += " , "; } string query = "update `survivor` s "; if (joinProfile) query += "join `profile` p on s.`unique_id` = p.`unique_id` "; query += "set " + setClause + " where s.`id` = " + lexical_cast<string>(characterID); //bool exRes = getDB()->execute(query.c_str()); //poco_assert(exRes == true); Poco::Data::Statement stmt((*activeSession)); stmt << query, now; } return true; };
TEST(DynTypedNode, StmtSourceRange) { RangeVerifier<DynTypedNode> Verifier; Verifier.expectRange(1, 10, 1, 11); EXPECT_TRUE(Verifier.match("void f() {}", stmt())); }
static void stmtlist() { stmt(); morestmts(); }
TEST(DynTypedNode, StmtPrint) { PrintVerifier Verifier; Verifier.expectString("{\n}\n"); EXPECT_TRUE(Verifier.match("void f() {}", stmt())); }
bool Database::deleteTrap(Int64 trapUID) { Poco::Data::Statement stmt((*activeSession)); stmt << "delete from `instance_traps` where `unique_id` = ? and `instance_id` = ?", use(trapUID), use(serverID), now; return true; }