本文整理汇总了C++中DatabaseResult类的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseResult类的具体用法?C++ DatabaseResult怎么用?C++ DatabaseResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: offsetof
void MessageRouter::_loadMessageProcessMap(void)
{
MessageRoute route;
// We need to populate our message map.
// setup our databinding parameters.
DataBinding* binding = mDatabase->createDataBinding(2);
binding->addField(DFT_uint32, offsetof(MessageRoute, mMessageId), 4);
binding->addField(DFT_uint32, offsetof(MessageRoute, mProcessId), 4);
// Execute our statement
DatabaseResult* result = mDatabase->executeSynchSql("SELECT messageId, processId FROM %s.config_message_routes;",mDatabase->galaxy());
uint32 count = static_cast<uint32>(result->getRowCount());
// Retrieve our routes and add them to the map.
for(uint32 i = 0; i < count; i++)
{
result->getNextRow(binding, &route);
mMessageRouteMap.insert(std::make_pair(route.mMessageId, route.mProcessId));
}
// Delete our DB objects.
mDatabase->destroyDataBinding(binding);
mDatabase->destroyResult(result);
}
示例2: new
//======================================================================================================================
DatabaseResult* DatabaseImplementationMySql::ExecuteSql(int8* sql,bool procedure)
{
DatabaseResult* newResult = new(ResultPool::ordered_malloc()) DatabaseResult(procedure);
newResult->setDatabaseImplementation(this);
// Execute the statement
uint32 len = (uint32)strlen(sql);
mysql_real_query(mConnection, sql, len);
if(mysql_errno(mConnection) != 0)
{
gLogger->log(LogManager::EMERGENCY, "DatabaseError: %s", mysql_error(mConnection));
}
mResultSet = mysql_store_result(mConnection);
newResult->setConnectionReference((void*)mConnection);
newResult->setResultSetReference((void*)mResultSet);
if (mResultSet)
{
newResult->setRowCount(mResultSet->row_count);
}
return newResult;
}
示例3: getDbConnection
std::vector<Device *> ControllerDatabaseFactory::fetchDevices(
const std::size_t id ) const {
std::vector<Device *> devices;
DatabaseStatement * statement;
DatabaseResult * result;
DatabaseResultRow * row;
std::string query;
std::size_t deviceId;
query =
"SELECT id "
"FROM devices "
"WHERE controller_id = ";
query = query + std::to_string(id);
statement = getDbConnection()->createStatement(query);
if( statement != nullptr ) {
result = statement->execute();
if( result != nullptr ) {
while( result->hasNext() ) {
row = result->next();
deviceId = static_cast<std::size_t>(
atol(row->getColumn(0).c_str()));
devices.push_back(mDeviceContainer->get(deviceId));
delete row;
}
delete result;
}
delete statement;
}
return ( devices );
}
示例4: throw
int Database::coutTables() throw()
{
if(dbStatus != SQLITE_OK)
throw DatabaseNotOpenException() << DebugInfo(TRACE(), DebugInfo::Error);
DatabaseResult res;
int tableCount = -1;
try
{
res = exec("SELECT COUNT(name) FROM ("
"SELECT name FROM sqlite_master "
"WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
"UNION ALL "
"SELECT name FROM sqlite_temp_master "
"WHERE type IN ('table','view') )");
tableCount = res.getRowData().at(0).getColumnData().at(0).getIntData();
} catch (...)
{
throw;
}
return tableCount;
}
示例5: restoreThoughts
void StorageManager::restoreThoughts(LocatedEntity * ent)
{
Database * db = Database::instance();
const DatabaseResult res = db->selectThoughts(ent->getId());
Atlas::Message::ListType thoughts_data;
DatabaseResult::const_iterator I = res.begin();
DatabaseResult::const_iterator Iend = res.end();
for (; I != Iend; ++I) {
const std::string thought = I.column("thought");
if (thought.empty()) {
log(ERROR,
compose("No thought column in property row for %1",
ent->getId()));
continue;
}
MapType thought_data;
db->decodeMessage(thought, thought_data);
thoughts_data.push_back(thought_data);
}
if (!thoughts_data.empty()) {
OpVector opRes;
Atlas::Objects::Operation::Think thoughtOp;
Atlas::Objects::Operation::Set setOp;
setOp->setArgsAsList(thoughts_data);
//Make the thought come from the entity itself
thoughtOp->setArgs1(setOp);
thoughtOp->setTo(ent->getId());
thoughtOp->setFrom(ent->getId());
ent->sendWorld(thoughtOp);
}
}
示例6:
std::shared_ptr<std::string> fCache::get(const std::string &key)
{
std::stringstream sql;
DatabaseResult result;
sql << "SELECT data FROM " << TABLE_NAME << " WHERE id='" << key << "';";
_db.executeSQL(sql.str().c_str(), result);
if(result.isOK())
{
///////////////////////////////////////////////////////////////////////////
// Update timestamp
sql.str("");
sql << "UPDATE " << TABLE_NAME << " SET timestamp=" << Timestamp::unixTime() << " WHERE id='" << key << "';";
_db.executeSQL(sql.str().c_str());
///////////////////////////////////////////////////////////////////////////
if(result.records.size()==1 && result.records[0].size() == 1)
{
auto readBuffer = std::make_shared<std::string>(std::move(result.records.at(0).at(0)));
if(!readBuffer->empty())
{
return readBuffer;
}
}
} else
{
AMIGO_LOG_E(TAG, "::get() sql failed: '%s'\n", sql.str().c_str());
}
return nullptr;
}
示例7: sprintf
NetworkClient* ServerManager::handleSessionConnect(Session* session, Service* service)
{
NetworkClient* newClient = 0;
ServerAddress serverAddress;
// Execute our statement
int8 sql[500];
sprintf(sql,"SELECT id, address, port, status, active FROM config_process_list WHERE address='%s' AND port=%u;", session->getAddressString(), session->getPortHost());
DatabaseResult* result = mDatabase->ExecuteSynchSql(sql);
// If we found them
if(result->getRowCount() == 1)
{
// Retrieve our routes and add them to the map.
result->GetNextRow(mServerBinding,&serverAddress);
// put this fresh data in our list.
newClient = new ConnectionClient();
ConnectionClient* connClient = reinterpret_cast<ConnectionClient*>(newClient);
ConnectionClient* oldClient = mServerAddressMap[serverAddress.mId].mConnectionClient;
if(oldClient)
{
delete(oldClient);
--mTotalConnectedServers;
}
connClient->setServerId(serverAddress.mId);
memcpy(&mServerAddressMap[serverAddress.mId], &serverAddress, sizeof(ServerAddress));
mServerAddressMap[serverAddress.mId].mConnectionClient = connClient;
gLogger->log(LogManager::DEBUG,"*** Backend server connected id: %u\n",mServerAddressMap[serverAddress.mId].mId);
// If this is one of the servers we're waiting for, then update our count
if(mServerAddressMap[serverAddress.mId].mActive)
{
++mTotalConnectedServers;
if(mTotalConnectedServers == mTotalActiveServers)
{
mDatabase->ExecuteProcedureAsync(0, 0, "CALL sp_GalaxyStatusUpdate(%u, %u);", 2, mClusterId); // Set status to online
}
}
}
else
{
gLogger->log(LogManager::CRITICAL,"*** Backend server connect error - Server not found in DB\n");
gLogger->log(LogManager::DEBUG,sql);
gLogger->log(LogManager::DEBUG,"\n");
}
// Delete our DB objects.
mDatabase->DestroyResult(result);
return(newClient);
}
示例8: readRuleTable
/// \brief Read all the rules in one ruleset from the rules table.
///
/// @param ruleset the name of the ruleset to be read.
/// @param o Atlas map to store the rules in.
void readRuleTable(const std::string & ruleset, MapType & o) {
std::stringstream query;
query << "SELECT * FROM " << m_connection.rule() << " WHERE "
<< " ruleset = '" << ruleset << "'";
DatabaseResult res = m_connection.runSimpleSelectQuery(query.str());
DatabaseResult::const_iterator I = res.begin();
DatabaseResult::const_iterator Iend = res.end();
for (; I != Iend; ++I) {
MapType & data = (o[I.column("id")] = MapType()).asMap();
m_connection.decodeMessage(I.column("contents"), data);
}
}
示例9: _getCacheSize
int fCache::_getCacheSize()
{
DatabaseResult result;
std::stringstream sql;
sql << "SELECT COUNT(*) FROM " << TABLE_NAME << " WHERE persistent=0;";
_db.executeSQL(sql.str().c_str(), result);
if(result.isOK() && result.records.size()==1 && result.records[0].size() == 1)
{
return atoi(result.records.at(0).at(0).c_str());
}
return -1;
}
示例10: isExist
bool fCache::isExist(const std::string &key)
{
std::stringstream sql;
DatabaseResult result;
sql << "SELECT EXISTS(SELECT 1 FROM " << TABLE_NAME << " WHERE id='" << key << "');";
_db.executeSQL(sql.str().c_str(), result);
bool exist=false;
if(result.isOK() && result.records.size()==1 && result.records[0].size() == 1)
{
exist = (atoi(result.records.at(0).at(0).c_str()) > 0);
}
return exist;
}
示例11: readRuleTableSets
/// \brief Read all the rules sets from the rules table
///
void readRuleTableSets(std::set<std::string> & sets) {
std::stringstream query;
query << "SELECT ruleset FROM " << m_connection.rule();
DatabaseResult res = m_connection.runSimpleSelectQuery(query.str());
DatabaseResult::const_iterator I = res.begin();
DatabaseResult::const_iterator Iend = res.end();
for (; I != Iend; ++I) {
std::string ruleset_name = I.column("ruleset");
if (sets.find(ruleset_name) == sets.end()) {
sets.insert(ruleset_name);
}
}
}
示例12: _processSelectCharacter
//======================================================================================================================
void ClientManager::_processSelectCharacter(ConnectionClient* client, Message* message)
{
uint64 characterId = message->getUint64();
DatabaseResult* result = mDatabase->executeSynchSql("SELECT planet_id FROM %s.characters WHERE id=%"PRIu64";",mDatabase->galaxy(), characterId);
uint32 serverId;
DataBinding* binding = mDatabase->createDataBinding(1);
binding->addField(DFT_uint32, 0, 4);
result->getNextRow(binding, &serverId);
client->setServerId(serverId + 8); // server ids for zones are planetId + 8;
mDatabase->destroyDataBinding(binding);
mDatabase->destroyResult(result);
// send an opClusterClientConnect message to zone server.
gMessageFactory->StartMessage();
gMessageFactory->addUint32(opClusterClientConnect);
gMessageFactory->addUint64(characterId);
Message* zoneMessage = gMessageFactory->EndMessage();
// This one goes to the ZoneServer the client is currently on.
zoneMessage->setAccountId(client->getAccountId());
zoneMessage->setDestinationId(static_cast<uint8>(serverId + 8));
zoneMessage->setRouted(true);
mMessageRouter->RouteMessage(zoneMessage, client);
// send an opClusterClientConnect message to chat server.
gMessageFactory->StartMessage();
gMessageFactory->addUint32(opClusterClientConnect);
gMessageFactory->addUint64(characterId);
gMessageFactory->addUint32(serverId);
Message* chatMessage = gMessageFactory->EndMessage();
// This one goes to the ChatServer
chatMessage->setAccountId(client->getAccountId());
chatMessage->setDestinationId(CR_Chat);
chatMessage->setRouted(true);
mMessageRouter->RouteMessage(chatMessage, client);
// Now send the SelectCharacter message off to the zone server.
gMessageFactory->StartMessage();
gMessageFactory->addData(message->getData(), message->getSize());
Message* selectMessage = gMessageFactory->EndMessage();
selectMessage->setAccountId(client->getAccountId());
selectMessage->setDestinationId(static_cast<uint8>(serverId + 8));
selectMessage->setRouted(true);
mMessageRouter->RouteMessage(selectMessage, client);
}
示例13: LoadCurrentGlobalTick
void WorldManager::LoadCurrentGlobalTick()
{
uint64 Tick;
DatabaseResult* temp = mDatabase->executeSynchSql("SELECT Global_Tick_Count FROM %s.galaxy WHERE galaxy_id = '2'",mDatabase->galaxy());
DataBinding* tickbinding = mDatabase->createDataBinding(1);
tickbinding->addField(DFT_uint64,0,8,0);
temp->getNextRow(tickbinding,&Tick);
mDatabase->destroyDataBinding(tickbinding);
mDatabase->destroyResult(temp);
LOG(info) << "Current global tick count [" << Tick << "]";
mTick = Tick;
mSubsystemScheduler->addTask(fastdelegate::MakeDelegate(this,&WorldManager::_handleTick),7,1000,NULL);
}
示例14: getCacheSize
long fCache::getCacheSize(bool persistent)
{
std::stringstream sql;
DatabaseResult result;
if(persistent)
sql << "SELECT SUM(LENGTH(data)) FROM " << TABLE_NAME << " WHERE persistent=" << persistent << "";
else
sql << "SELECT SUM(LENGTH(data)) FROM " << TABLE_NAME;
_db.executeSQL(sql.str().c_str(), result);
if(result.isOK())
{
if(result.records.size()==1 && result.records[0].size() == 1)
{
std::string cacheSize = result.records.at(0).at(0);
return atol(cacheSize.c_str());
}
}
return 0;
}
示例15: restoreChildren
void StorageManager::restoreChildren(LocatedEntity * parent)
{
Database * db = Database::instance();
DatabaseResult res = db->selectEntities(parent->getId());
EntityBuilder * eb = EntityBuilder::instance();
// Iterate over res creating entities, and sorting out position, location
// and orientation. Restore children, but don't restore any properties yet.
DatabaseResult::const_iterator I = res.begin();
DatabaseResult::const_iterator Iend = res.end();
for (; I != Iend; ++I) {
const std::string id = I.column("id");
const int int_id = forceIntegerId(id);
const std::string type = I.column("type");
//By sending an empty attributes pointer we're telling the builder not to apply any default
//attributes. We will instead apply all attributes ourselves when we later on restore attributes.
Atlas::Objects::SmartPtr<Atlas::Objects::Entity::RootEntityData> attrs(nullptr);
LocatedEntity * child = eb->newEntity(id, int_id, type, attrs, BaseWorld::instance());
if (!child) {
log(ERROR, compose("Could not restore entity with id %1 of type %2"
", most likely caused by this type missing.",
id, type));
continue;
}
const std::string location_string = I.column("location");
MapType loc_data;
db->decodeMessage(location_string, loc_data);
child->m_location.readFromMessage(loc_data);
if (!child->m_location.pos().isValid()) {
std::cout << "No pos data" << std::endl << std::flush;
log(ERROR, compose("Entity %1 restored from database has no "
"POS data. Ignored.", child->getId()));
delete child;
continue;
}
child->m_location.m_loc = parent;
child->setFlags(entity_clean | entity_pos_clean | entity_orient_clean);
BaseWorld::instance().addEntity(child);
restoreChildren(child);
}
}