//returns the itemID of the active clone
//if you want to get the typeID of the clone, please use GetActiveCloneType
bool CharacterDB::GetActiveClone(uint32 characterID, uint32 &itemID) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
                           "SELECT"
                           "  itemID"
                           " FROM entity"
                           " WHERE ownerID = %u"
                           " and flag='400'"
                           " and customInfo='active'",
                           characterID))
    {
        _log(DATABASE__ERROR, "Failed to query active clone of char %u: %s.", characterID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    res.GetRow(row);
    itemID=row.GetUInt(0);

    return true;
}
Example #2
0
uint32 RamProxyDB::GetRegionOfContainer(const uint32 containerID) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
                "SELECT regionID"
                " FROM ramAssemblyLineStations"
                " WHERE stationID = %u",
                containerID))
    {
        _log(DATABASE__ERROR, "Unable to query region for container %u: %s", containerID, res.error.c_str());
        return 0;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(DATABASE__ERROR, "No region found for container %u.", containerID);
        return 0;
    }

    return(row.GetUInt(0));

}
Example #3
0
PyDict *DBResultToIntIntDict(DBQueryResult &result) {
    PyDict *res = new PyDict();

    //add a line entry for each result row:
    DBResultRow row;
    while(result.GetRow(row)) {
        if(row.IsNull(0))
            continue;   //no working with NULL keys...
        int32 k = row.GetInt(0);
        if(k == 0)
            continue;   //likely a non-integer key
        int32 v;
        if(row.IsNull(1))
            v = 0;      //we can deal with assuming NULL == 0
        else
            v = row.GetInt(1);

        res->SetItem( new PyInt(k), new PyInt(v) );
    }

    return res;
}
Example #4
0
//replace all the typeID of the character's clones
bool CorporationDB::ChangeCloneType(uint32 characterID, uint32 typeID) {
    DBQueryResult res;

    if(sDatabase.RunQuery(res,
        "SELECT "
        " typeID, typeName "
        "FROM "
        " invTypes "
        "WHERE typeID = %u",
        typeID))
    {
        _log(DATABASE__ERROR, "Failed to change clone type of char %u: %s.", characterID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    if( !(res.GetRow(row)) )
    {
        sLog.Error( "CorporationDB::ChangeCloneType()", "Could not find Clone typeID = %u in invTypes table.", typeID );
        return false;
    }
    std::string typeNameString = row.GetText(1);

    if(sDatabase.RunQuery(res,
        "UPDATE "
        "entity "
        "SET typeID=%u, itemName='%s' "
        "where ownerID=%u "
        "and flag='400'",
        typeID,
        typeNameString.c_str(),
        characterID))
    {
        _log(DATABASE__ERROR, "Failed to change clone type of char %u: %s.", characterID, res.error.c_str());
        return false;
    }
    sLog.Debug( "CorporationDB", "Clone upgrade successful" );
    return true;
}
uint32 CorporationDB::GetQuoteForRentingAnOffice(uint32 stationID) {
    DBQueryResult res;
    DBResultRow row;

    if (!sDatabase.RunQuery(res,
        " SELECT "
        " officeRentalCost "
        " FROM staStations "
        " WHERE staStations.stationID = %u ", stationID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        // Try to look more clever than we actually are...
        return 10000;
    }

    if (!res.GetRow(row)) {
        codelog(SERVICE__ERROR, "Unable to find station data, stationID: %u", stationID);
        // Try to look more clever than we actually are...
        return 10000;
    }

    return row.GetUInt(0);
}
Example #6
0
bool ReprocessingDB::GetRecoverables(const uint32 typeID, std::vector<Recoverable> &into) {
	DBQueryResult res;
	DBResultRow row;

	if (!sDatabase.RunQuery(res,
		"SELECT materialTypeID, MIN(quantity) FROM invTypeMaterials WHERE typeID = %u"
		" GROUP BY materialTypeID",
		typeID))
	{
		_log(DATABASE__ERROR, "Unable to get recoverables for type ID %u: '%s'", typeID, res.error.c_str());
		return false;
	}

	Recoverable rec;

	while (res.GetRow(row)) {
		rec.typeID = row.GetInt(0);
		rec.amountPerBatch = row.GetInt(1);
		into.push_back(rec);
	}

	return true;
}
Example #7
0
void DGM_Ship_Bonus_Modifiers_Table::_Populate()
{
    //first get list of all effects from dgmShipBonusModifiers table
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetAllDgmShipBonusModifiers(*res);

    //counter
    ShipBonusModifier * mShipBonusModifierPtr;
    mShipBonusModifierPtr = NULL;
    uint32 shipID;

	uint32 total_modifier_count = 0;
	uint32 error_count = 0;

	//go through and populate each ship bonus modifier
    DBResultRow row;
    while( res->GetRow(row) )
    {
        shipID = row.GetInt(0);
        mShipBonusModifierPtr = new ShipBonusModifier(shipID);
		if( mShipBonusModifierPtr->IsModifierLoaded() )
			m_ShipBonusModifiersMap.insert(std::pair<uint32, ShipBonusModifier *>(shipID,mShipBonusModifierPtr));
		else
			error_count++;

		total_modifier_count++;
    }

	if( error_count > 0 )
		sLog.Error("DGM_Ship_Bonus_Modifiers_Table::_Populate()","ERROR Populating the DGM_Ship_Bonus_Modifiers_Table memory object: %u of %u ship bonus modifiers failed to load!", error_count, total_modifier_count);

	sLog.Log("DGM_Ship_Bonus_Modifiers_Table", "..........%u total modifier objects loaded", total_modifier_count);

    //cleanup
    delete res;
    res = NULL;
}
Example #8
0
void DGM_Effects_Table::_Populate()
{
    //first get list of all effects from dgmEffects table
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetAllDgmEffects(*res);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    uint32 effectID;

	uint32 total_effect_count = 0;
	uint32 error_count = 0;

	//go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        effectID = row.GetInt(0);
        mEffectPtr = new MEffect(effectID);
		if( mEffectPtr->IsEffectLoaded() )
			m_EffectsMap.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
		else
			error_count++;

		total_effect_count++;
    }

	if( error_count > 0 )
		sLog.Error("DGM_Effects_Table::_Populate()","ERROR Populating the DGM_Effects_Table memory object: %u of %u effects failed to load!", error_count, total_effect_count);

	sLog.Log("DGM_Effects_Table", "..........%u total effects objects loaded", total_effect_count);

    //cleanup
    delete res;
    res = NULL;
}
Example #9
0
// TODO: hangarGraphicID went missing. maybe no longer in the dump?
PyRep *StationDB::GetStationItemBits(uint32 sid) {
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		" SELECT "
		" staStations.stationID, "
		" staStations.stationTypeID, staStations.corporationID AS ownerID, "
		" staStationTypes.hangarGraphicID, "
		// damn mysql returns the result of the sum as string and so it is sent to the client as string and so it freaks out...
		" CAST(SUM(staOperationServices.serviceID) as UNSIGNED INTEGER) AS serviceMask "
		" FROM staStations "
		" LEFT JOIN staStationTypes ON staStations.stationTypeID = staStationTypes.stationTypeID "
		" LEFT JOIN staOperationServices ON staStations.operationID = staOperationServices.operationID "
		" WHERE staStations.stationID = %u "
		" GROUP BY staStations.stationID ", sid
	))
	{
		_log(SERVICE__ERROR, "Error in GetStationItemBits query: %s", res.error.c_str());
		return NULL;
	}

	DBResultRow row;
	if(!res.GetRow(row)) {
		_log(SERVICE__ERROR, "Error in GetStationItemBits query: no station for id %d", sid);
		return NULL;
	}

	PyTuple * result = new PyTuple(5);
	result->SetItem(0, new PyInt(row.GetUInt(3)));
	result->SetItem(1, new PyInt(row.GetUInt(2)));
	result->SetItem(2, new PyInt(row.GetUInt(0)));
	result->SetItem(3, new PyInt(row.GetUInt(4)));
	result->SetItem(4, new PyInt(row.GetUInt(1)));

	return result;
}
Example #10
0
// Return the Home station of the char based on the active clone
bool CharacterDB::GetCharHomeStation(uint32 characterID, uint32 &stationID) {
	uint32 activeCloneID;
	if( !GetActiveClone(characterID, activeCloneID) )
	{
		_log( DATABASE__ERROR, "Could't get the active clone for char %u", characterID );
		return false;
	}

	DBQueryResult res;
	if( !sDatabase.RunQuery(res,
		"SELECT locationID "
		"FROM entity "
		"WHERE itemID = %u",
		activeCloneID ))
	{
		_log(DATABASE__ERROR, "Could't get the location of the clone for char %u", characterID );
		return false;
	}

	DBResultRow row;
    res.GetRow(row);
    stationID = row.GetUInt(0);
	return true;
}
Example #11
0
uint32 BookmarkDB::GetNextAvailableBookmarkID()
{
	DBQueryResult res;

	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	bookmarkID "
		" FROM bookmarks "
		" WHERE bookmarkID >= %u ", 0))
	{
        sLog.Error( "BookmarkDB::GetNextAvailableBookmarkID()", "Error in query: %s", res.error.c_str() );
		return 0;
	}

	uint32 currentBookmarkID = 0;

	// Traverse through the rows in the query result until the first gap is found
	// and return the value that would be first (or only one) in the gap as the next
	// free bookmark ID:
	DBResultRow row;
	while( res.GetRow(row) )
	{
        const uint32 bookmarkID = row.GetUInt( 0 );

        if( currentBookmarkID < bookmarkID )
            return currentBookmarkID;

        ++currentBookmarkID;
	}

        // Check to make sure that the next available bookmarkID is not equal to the Maximum bookmarkID value
	if( currentBookmarkID <= BookmarkService::MAX_BOOKMARK_ID )
        return currentBookmarkID;
	else
        return 0;	// No free bookmarkIDs found (this should never happen as there are way too many IDs to exhaust)
}
Example #12
0
bool DBQueryResult::GetRow( DBResultRow& into )
{
    if( NULL == mResult )
        return false;

    MYSQL_ROW row = mysql_fetch_row( mResult );
    if( NULL == row )
        return false;

    const unsigned long* lengths = mysql_fetch_lengths( mResult );
    if( NULL == lengths )
        return false;

    into.SetData( this, row, lengths );
    return true;
}
Example #13
0
bool MarketDB::GetOrderInfo(uint32 orderID, uint32 *orderOwnerID, uint32 *typeID, uint32 *stationID, uint32 *quantity, double *price, bool *isBuy, bool *isCorp) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        " volRemaining,"
        " price,"
        " typeID,"
        " stationID,"
        " charID,"
        " bid,"
        " isCorp"
        " FROM market_orders"
        " WHERE orderID=%u",
        orderID))
    {
        _log(MARKET__ERROR, "Error in query: %s.", res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(MARKET__ERROR, "Order %u not found.", orderID);
        return false;
    }

    if(quantity != NULL)
        *quantity = row.GetUInt(0);
    if(price != NULL)
        *price = row.GetDouble(1);
    if(typeID != NULL)
        *typeID = row.GetUInt(2);
    if(stationID != NULL)
        *stationID = row.GetUInt(3);
    if(orderOwnerID != NULL)
        *orderOwnerID = row.GetUInt(4);
    if(isBuy != NULL)
        *isBuy = row.GetInt(5) ? true : false;
    if(isCorp != NULL)
        *isCorp = row.GetInt(6) ? true : false;

    return true;
}
Example #14
0
/**
  * @todo Here should come a call to Corp??::CharacterJoinToCorp or what the heck... for now we only put it there
  */
bool CharacterDB::GetLocationCorporationByCareer(CharacterData &cdata) {
	DBQueryResult res;
	if (!sDatabase.RunQuery(res, 
	 "SELECT "
	 "  chrSchools.corporationID, "
	 "  chrSchools.schoolID, "
	 "  corporation.allianceID, "
	 "  corporation.stationID, "
	 "  staStations.solarSystemID, "
	 "  staStations.constellationID, "
	 "  staStations.regionID "
	 " FROM staStations"
	 "  LEFT JOIN corporation ON corporation.stationID=staStations.stationID"
	 "  LEFT JOIN chrSchools ON corporation.corporationID=chrSchools.corporationID"
	 "  LEFT JOIN chrCareers ON chrSchools.careerID=chrCareers.careerID"
	 " WHERE chrCareers.careerID = %u", cdata.careerID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return (false);
	}
	
	DBResultRow row;
	if(!res.GetRow(row)) {
		codelog(SERVICE__ERROR, "Failed to find career %u", cdata.careerID);
		return false;
	}
	
	cdata.corporationID = row.GetUInt(0);
	cdata.schoolID = row.GetUInt(1);
	cdata.allianceID = row.GetUInt(2);

	cdata.stationID = row.GetUInt(3);
	cdata.solarSystemID = row.GetUInt(4);
	cdata.constellationID = row.GetUInt(5);
	cdata.regionID = row.GetUInt(6);

	return (true);
}
Example #15
0
bool ServiceDB::GetStaticItemInfo(uint32 itemID, uint32 *systemID, uint32 *constellationID, uint32 *regionID, GPoint *position) {
    if(       systemID == NULL
        && constellationID == NULL
        && regionID == NULL
        && position == NULL
    )
        return true;

    DBQueryResult res;
    if(!DBcore::RunQuery(res,
        "SELECT"
        " solarSystemID,"
        " constellationID,"
        " regionID,"
        " x, y, z"
        " FROM mapDenormalize"
        " WHERE itemID = %u",
        itemID))
    {
        _log(DATABASE__ERROR, "Failed to query info for static item %u: %s.", itemID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(DATABASE__ERROR, "Failed to query info for static item %u: Item not found.", itemID);
        return false;
    }

    if(systemID != NULL)
        *systemID = row.GetUInt(0);
    if(constellationID != NULL)
        *constellationID = row.GetUInt(1);
    if(regionID != NULL)
        *regionID = row.GetUInt(2);
    if(position != NULL)
        *position = GPoint(
            row.GetDouble(3),
            row.GetDouble(4),
            row.GetDouble(5)
        );

    return true;
}
Example #16
0
AgentLevel *MissionDB::LoadAgentLevel(uint8 level) {
	AgentLevel *result = new AgentLevel;
	
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		"SELECT missionID,missionName,missionLevel,"
		"	agtMissions.missionTypeID,missionTypeName,"
		"	importantMission"
		" FROM agtMissions"
		"	NATURAL JOIN agtMissionTypes"
		" WHERE missionLevel=%d",
		level
	))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		delete result;
		return NULL;
	}

	std::vector<uint32> IDs;
	DBResultRow row;

	IDs.clear();
	while(res.GetRow(row)) {
		AgentMissionSpec *spec = new AgentMissionSpec;
		spec->missionID = row.GetUInt(0);
		spec->missionName = row.GetText(1);
		spec->missionLevel = row.GetUInt(2);
		spec->missionTypeID = row.GetUInt(3);
		spec->missionTypeName = row.GetText(1);
		spec->importantMission = (row.GetUInt(2)==0)?false:true;
		result->missions.push_back(spec);
	}
	
}
Example #17
0
bool ServiceDB::GetSystemInfo(uint32 systemID, uint32 *constellationID, uint32 *regionID, std::string *name, std::string *securityClass) {
    if(       constellationID == NULL
        && regionID == NULL
        && name == NULL
        && securityClass == NULL
    )
        return true;

    DBQueryResult res;
    if(!DBcore::RunQuery(res,
        "SELECT"
        " constellationID,"
        " regionID,"
        " solarSystemName,"
        " securityClass"
        " FROM mapSolarSystems"
        " WHERE solarSystemID = %u",
        systemID))
    {
        _log(DATABASE__ERROR, "Failed to query info for system %u: %s.", systemID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(DATABASE__ERROR, "Failed to query info for system %u: System not found.", systemID);
        return false;
    }

    if(constellationID != NULL)
        *constellationID = row.GetUInt(0);
    if(regionID != NULL)
        *regionID = row.GetUInt(1);
    if(name != NULL)
        *name = row.GetText(2);
    if(securityClass != NULL)
        *securityClass = row.IsNull(3) ? "" : row.GetText(3);

    return true;
}
Example #18
0
bool CommandDB::ItemSearch(uint32 typeID, uint32 &actualTypeID,
    std::string &actualTypeName, uint32 &actualGroupID, uint32 &actualCategoryID, double &actualRadius)
{
    DBQueryResult result;
    DBResultRow row;

    if (!sDatabase.RunQuery(result,
        "SELECT  "
        " invTypes.typeID,"
        " invTypes.typeName,"
        " invTypes.groupID,"
        " invTypes.radius,"
        " invGroups.categoryID"
        " FROM invTypes"
        "  LEFT JOIN invGroups"
        "   ON invGroups.groupID = invTypes.groupID"
        " WHERE typeID = %u",
        typeID
        ))
    {
        sLog.Error( "CommandDB::ItemSearch()", "Error in query: %s", result.error.c_str() );
        return (false);
    }

    if( !result.GetRow(row) )
    {
        sLog.Error( "CommandDB::ItemSearch()", "Query returned NO results: %s", result.error.c_str() );
        return (false);
    }

    // Extract values from the first row:
    actualTypeID = row.GetUInt( 0 );
    actualTypeName = row.GetText( 1 );
    actualGroupID = row.GetUInt( 2 );
    actualCategoryID = row.GetUInt( 4 );
    actualRadius = row.GetDouble( 3 );

    return true;
}
dgmtypeattributemgr::dgmtypeattributemgr()
{
    // load shit from db
    DBQueryResult res;

    if( !DBcore::RunQuery( res,
        "SELECT * FROM dgmTypeAttributes ORDER BY typeID" ) )
    {
        SysLog::Error("DgmTypeAttrMgr", "Error in db load query: %s", res.error.c_str());
        return;
    }

    uint32 currentID = 0;
    DgmTypeAttributeSet * entry = NULL;
    DBResultRow row;

    int amount = res.GetRowCount();
    for (int i = 0; i < amount; i++)
    {
        res.GetRow(row);
        uint32 typeID = row.GetUInt(0);

        if (currentID != typeID) {
            currentID = typeID;
            entry = new DgmTypeAttributeSet;
            mDgmTypeAttrInfo.insert(std::make_pair(currentID, entry));
        }

        DgmTypeAttribute * attr_entry = new DgmTypeAttribute();
        attr_entry->attributeID = row.GetUInt(1);
        if (row.IsNull(2) == true) {
            attr_entry->number = EvilNumber(row.GetFloat(3));
        } else {
            attr_entry->number = EvilNumber(row.GetInt(2));
        }

        entry->attributeset.push_back(attr_entry);
    }
}
Example #20
0
// Function: Query 'channels' table for the channel whose 'channelID' matches the ID specified,
// then return all parameters for that channel.
void LSCDB::GetChannelInformation(uint32 channelID, std::string & name,
	    std::string & motd, uint32 & ownerid, std::string & compkey,
	    bool & memberless, std::string & password, bool & maillist,
	    uint32 & cspa, uint32 & temp, uint32 & mode)
{
	DBQueryResult res;

	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	channelID, "
		"	displayName, "
		"   motd, "
		"   ownerID, "
		"   comparisonKey, "
		"   memberless, "
		"   password, "
		"   mailingList, "
		"   cspa, "
		"   temporary, "
		"   mode "
		" FROM channels "
		" WHERE channelID = %u", channelID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return;
	}

	DBResultRow row;

	if (!(res.GetRow(row)))
	{
            _log(SERVICE__ERROR, "Channel named '%s' isn't present in the database", name.c_str() );
            return;
	}

	name = (row.GetText(1) == NULL ? "" : row.GetText(1));	// empty displayName field in channels table row returns NULL, so fill this string with "" in that case
	motd = (row.GetText(2) == NULL ? "" : row.GetText(2));	// empty motd field in channels table row returns NULL, so fill this string with "" in that case
	ownerid = row.GetUInt(3);
	compkey = (row.GetText(4) == NULL ? "" : row.GetText(4));	// empty comparisonKey field in channels table row returns NULL, so fill this string with "" in that case
	memberless = row.GetUInt(5) ? true : false;
	password = (row.GetText(6) == NULL ? "" : row.GetText(6));	// empty password field in channels table row returns NULL, so fill this string with "" in that case
	maillist = row.GetUInt(7) ? true : false;
	cspa = row.GetUInt(8);
	temp = row.GetUInt(9);
	mode = row.GetUInt(10);
}
Example #21
0
//void CharacterDB::GetCharacterData(uint32 characterID, std::vector<uint32> &characterDataVector) {
void CharacterDB::GetCharacterData(uint32 characterID, std::map<std::string, uint32> &characterDataMap) {

	DBQueryResult res;
    DBResultRow row;

    if(!sDatabase.RunQuery(res,
        "SELECT "
        "  character_.corporationID, "
        "  character_.stationID, "
        "  character_.solarSystemID, "
        "  character_.constellationID, "
        "  character_.regionID, "
        "  corporation.stationID, "
        "  character_.corpRole, "
        "  character_.rolesAtAll, "
        "  character_.rolesAtBase, "
        "  character_.rolesAtHQ, "
        "  character_.rolesAtOther, "
        "  entity.locationID "
        " FROM character_ "
        "  LEFT JOIN corporation USING (corporationID) "
        "  LEFT JOIN entity ON entity.itemID = character_.characterID "
        " WHERE characterID = %u",
        characterID))
    {
        sLog.Error("CharacterDB::GetCharPublicInfo2()", "Failed to query HQ of character's %u corporation: %s.", characterID, res.error.c_str());
    }

	if(!res.GetRow(row))
    {
        sLog.Error("CharacterDB::GetCharacterData()", "No valid rows were returned by the database query.");
	}
	
//    std::map<std::string,uint32> characterDataMap;
//    for( uint32 i=0; i<=characterDataVector.size(); i++ )
//        characterDataVector.push_back( row.GetUInt(i) );

    characterDataMap["corporationID"] = row.GetUInt(0);
    characterDataMap["stationID"] = row.GetUInt(1);
    characterDataMap["solarSystemID"] = row.GetUInt(2);
    characterDataMap["constellationID"] = row.GetUInt(3);
    characterDataMap["regionID"] = row.GetUInt(4);
    characterDataMap["corporationHQ"] = row.GetUInt(5);
    characterDataMap["corpRole"] = row.GetUInt(6);
    characterDataMap["rolesAtAll"] = row.GetUInt(7);
    characterDataMap["rolesAtBase"] = row.GetUInt(8);
    characterDataMap["rolesAtHQ"] = row.GetUInt(9);
    characterDataMap["rolesAtOther"] = row.GetUInt(10);
    characterDataMap["locationID"] = row.GetUInt(11);
}
Example #22
0
//this is a crap load of work... there HAS to be a better way to do this..
PyRep *MarketDB::GetMarketGroups() {
    
    DBQueryResult res;
    DBResultRow row;

    if(!sDatabase.RunQuery(res,
        "SELECT * "
        " FROM invMarketGroups"))
    {
        codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

	DBRowDescriptor *header = new DBRowDescriptor(res);
    
    CFilterRowSet *filterRowset = new CFilterRowSet(&header);
    
    PyDict *keywords = filterRowset->GetKeywords();
	keywords->SetItemString("giveMeSets", new PyBool(false)); //+
	keywords->SetItemString("allowDuplicateCompoundKeys", new PyBool(false)); //+
	keywords->SetItemString("indexName", new PyNone); //+
	keywords->SetItemString("columnName", new PyString("parentGroupID")); //+
    std::map< int, PyRep* > tt;

    while( res.GetRow(row) )
    {
        int parentGroupID = ( row.IsNull( 0 ) ? -1 : row.GetUInt( 0 ) );
        PyRep *pid;
        CRowSet *rowset;
        if(tt.count(parentGroupID) == 0) {
            pid = parentGroupID!=-1 ? (PyRep*)new PyInt(parentGroupID) : (PyRep*)new PyNone();
            tt.insert( std::pair<int, PyRep*>(parentGroupID, pid) );
            rowset = filterRowset->NewRowset(pid);
        } else {
            pid = tt[parentGroupID];
            rowset = filterRowset->GetRowset(pid);
        }
        
        PyPackedRow* pyrow = rowset->NewRow();

        pyrow->SetField((uint32)0, pid); //prentGroupID
        pyrow->SetField(1, new PyInt(row.GetUInt( 1 ) ) ); //marketGroupID
        pyrow->SetField(2, new PyString(row.GetText( 2 ) ) ); //marketGroupName
        pyrow->SetField(3, new PyString(row.GetText( 3 ) ) ); //description
        pyrow->SetField(4, row.IsNull( 4 ) ? 
            (PyRep*)(new PyNone()) : new PyInt(row.GetUInt( 4 ))  ); //graphicID
        pyrow->SetField(5, new PyBool(row.GetBool( 5 ) ) ); //hasTypes
        pyrow->SetField(6, row.IsNull( 6 ) ? 
            (PyRep*)(new PyNone()) : new PyInt(row.GetUInt( 6 ))  ); // iconID 
        pyrow->SetField(7, new PyInt( row.GetUInt(7) )  ); //dataID
        pyrow->SetField(8, new PyInt( row.GetUInt(8) )  ); //marketGroupNameID
        pyrow->SetField(9, new PyInt( row.GetUInt(9) )  ); //descriptionID
    }

    return filterRowset;
}
Example #23
0
bool BookmarkDB::GetBookmarkInformation(uint32 bookmarkID, uint32 &ownerID, uint32 &itemID, uint32 &typeID,
                                        uint32 &flag, std::string &memo, uint64 &created, double &x, double &y,
                                        double &z, uint32 &locationID, std::string &note, uint32 &creatorID,
                                        uint32 folderID)
{
    DBQueryResult res;
       DBResultRow row;

    // Query database 'srvBookmarks' table for the supplied bookmarkID and retrieve entire row:
    if (!DBcore::RunQuery(res,
        " SELECT "
        "    bookmarkID, "
        "   ownerID, "
        "   itemID, "
        "   typeID, "
        "   flag, "
        "   memo, "
        "   created, "
        "   x, "
        "   y, "
        "   z, "
        "   locationID, "
        "  note,"
        "  creatorID,"
        "  folderID"
        " FROM srvBookmarks "
        " WHERE bookmarkID = %u ", bookmarkID))
    {
        SysLog::Error( "BookmarkDB::GetBookmarkInformation()", "Error in query: %s", res.error.c_str() );
        return false;
    }

    // Query went through, but check to see if there were zero rows, ie bookmarkID was invalid:
    if ( !(res.GetRow(row)) )
        return false;

    // Bookmark 'bookmarkID' was found, Send back bookmark information:
    ownerID = row.GetUInt(1);
    itemID = row.GetUInt(2);
    typeID = row.GetUInt(3);
    flag = row.GetUInt(4);
    memo = row.GetText(5);
    created = row.GetUInt64(6);
    x = row.GetDouble(7);
    y = row.GetDouble(8);
    z = row.GetDouble(9);
    locationID = row.GetUInt(10);
    note = row.GetUInt(11);
    creatorID = row.GetUInt(12);
    folderID = row.GetUInt(13);

    return true;
}
Example #24
0
bool CorporationDB::CreateCorporationCreatePacket(Notify_OnCorporaionChanged & cc, uint32 oldCorpID, uint32 newCorpID) {
    DBQueryResult res;
    DBResultRow row;

    if (!sDatabase.RunQuery(res,
        " SELECT "
        "   corporationID,corporationName,description,tickerName,url,"
        "   taxRate,minimumJoinStanding,corporationType,hasPlayerPersonnelManager,"
        "   sendCharTerminationMessage,creatorID,ceoID,stationID,raceID,"
        "   allianceID,shares,memberCount,memberLimit,allowedMemberRaceIDs,"
        "   graphicID,shape1,shape2,shape3,color1,color2,color3,typeface,"
        "   division1,division2,division3,division4,division5,division6,"
        "   division7,deleted"
        " FROM corporation "
        " WHERE corporationID = %u ", newCorpID
        ))
    {
        codelog(SERVICE__ERROR, "Error in retrieving new corporation's data (%u)", newCorpID);
        return false;
    }

    if(!res.GetRow(row)) {
        codelog(SERVICE__ERROR, "Unable to find corporation's data (%u)", newCorpID);
        return false;
    }

    cc.allianceIDOld = new PyNone();
    cc.allowedMemberRaceIDsOld = new PyNone();
    cc.ceoIDOld = new PyNone();
    cc.color1Old = new PyNone();
    cc.color2Old = new PyNone();
    cc.color3Old = new PyNone();
    cc.corporationIDOld = new PyNone();
    cc.corporationNameOld = new PyNone();
    cc.corporationTypeOld = new PyNone();
    cc.creatorIDOld = new PyNone();
    cc.deletedOld = new PyNone();
    cc.descriptionOld = new PyNone();
    cc.division1Old = new PyNone();
    cc.division2Old = new PyNone();
    cc.division3Old = new PyNone();
    cc.division4Old = new PyNone();
    cc.division5Old = new PyNone();
    cc.division6Old = new PyNone();
    cc.division7Old = new PyNone();
    cc.graphicIDOld = new PyNone();
    cc.hasPlayerPersonnelManagerOld = new PyNone();
    cc.memberCountOld = new PyNone();
    cc.memberLimitOld = new PyNone();
    cc.minimumJoinStandingOld = new PyNone();
    cc.raceIDOld = new PyNone();
    cc.sendCharTerminationMessageOld = new PyNone();
    cc.shape1Old = new PyNone();
    cc.shape2Old = new PyNone();
    cc.shape3Old = new PyNone();
    cc.sharesOld = new PyNone();
    cc.stationIDOld = new PyNone();
    cc.taxRateOld = new PyNone();
    cc.tickerNameOld = new PyNone();
    cc.typefaceOld = new PyNone();
    cc.urlOld = new PyNone();

    cc.corporationIDNew = row.GetUInt(0);
    cc.corporationNameNew = row.GetText(1);
    cc.descriptionNew = row.GetText(2);
    cc.tickerNameNew = row.GetText(3);
    cc.urlNew = row.GetText(4);
    cc.taxRateNew = row.GetDouble(5);
    cc.minimumJoinStandingNew = row.GetDouble(6);
    cc.corporationTypeNew = row.GetUInt(7);
    cc.hasPlayerPersonnelManagerNew = row.GetUInt(8);
    cc.sendCharTerminationMessageNew = row.GetUInt(9);
    cc.creatorIDNew = row.GetUInt(10);
    cc.ceoIDNew = row.GetUInt(11);
    cc.stationIDNew = row.GetUInt(12);
    _NI(raceIDNew, 13);
    _NI(allianceIDNew, 14);
    cc.sharesNew = row.GetUInt64(15);
    cc.memberCountNew = row.GetUInt(16);
    cc.memberLimitNew = row.GetUInt(17);
    cc.allowedMemberRaceIDsNew = row.GetUInt(18);
    cc.graphicIDNew = row.GetUInt(19);
    _NI(shape1New, 20);
    _NI(shape2New, 21);
    _NI(shape3New, 22);
    _NI(color1New, 23);
    _NI(color2New, 24);
    _NI(color3New, 25);
    _NI(typefaceNew, 26);
    _NI(division1New, 27);
    _NI(division2New, 28);
    _NI(division3New, 29);
    _NI(division4New, 30);
    _NI(division5New, 31);
    _NI(division6New, 32);
    _NI(division7New, 33);
    cc.deletedNew = row.GetUInt(34);

    return true;
}
Example #25
0
bool SystemDB::LoadSystemDynamicEntities(uint32 systemID, std::vector<DBSystemDynamicEntity> &into) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    entity.itemID,"
        "   entity.itemName,"
        "    entity.typeID,"
        "   entity.ownerID,"
        "   entity.locationID,"
        "   entity.flag,"
        "    invTypes.groupID,"
        "    invGroups.categoryID,"
        "   0,"//"   character_.corporationID,"
        "   0,"//"   corporation.allianceID,"
        "   x,"
        "   y,"
        "   z"
        " FROM entity, invTypes, invGroups"//, character_, corporation"
        " WHERE"
        "        entity.typeID=invTypes.typeID"
        "    AND invTypes.groupID=invGroups.groupID"
        "    AND invGroups.categoryID NOT IN (%d,%d)"
        //"   AND character_.characterID = entity.ownerID"
        //"   AND corporation.corporationID = character_.corporationID"
        "    AND locationID=%u",
        //excluded categories:
            //celestials:
            EVEDB::invCategories::_System, EVEDB::invCategories::Station,
            //NPCs:
            //EVEDB::invCategories::Entity,
        systemID
    ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;
    DBSystemDynamicEntity entry;
    while(res.GetRow(row)) {
        entry.itemID = row.GetInt(0);
        entry.itemName = row.GetText(1);
        entry.typeID = row.GetInt(2);
        entry.ownerID = row.GetInt(3);
        entry.locationID = row.GetInt(4);
        entry.flag = row.GetInt(5);
        entry.groupID = row.GetInt(6);
        entry.categoryID = row.GetInt(7);
        entry.corporationID = row.GetInt(8);
        entry.allianceID = row.GetInt(9);
        entry.x = row.GetDouble(10);
        entry.y = row.GetDouble(11);
        entry.z = row.GetDouble(12);
        into.push_back(entry);
    }

    return true;
}
Example #26
0
void ModuleEffects::_populate(uint32 typeID)
{
    //first get list of all of the effects associated with the typeID
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetDgmTypeEffectsInformation(typeID, *res);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    m_defaultEffect = NULL;     // Set this to NULL until the default effect is found, if there is any
    uint32 effectID;
    uint32 isDefault;

    //go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        effectID = row.GetInt(0);
        isDefault = row.GetInt(1);
        switch( effectID )
        {
            case 11:    // loPower
            case 12:    // hiPower
            case 13:    // medPower
                // We do not need to make MEffect objects these effectIDs, since they do nothing
                mEffectPtr = NULL;
                break;

            default:
                mEffectPtr = new MEffect( effectID );
                break;
        }

        if( isDefault > 0 )
            m_defaultEffect = mEffectPtr;

        // This switch is assuming that all entries in 'dgmEffectsInfo' for this effectID are applied during the same module state,
        // which should really be the case anyway, for every effectID, so we just check index 0 of the effectIDs list of attributes
        // that are modified by this effect for which module state during which the effect is active:
        if( mEffectPtr != NULL )
        {
            switch( mEffectPtr->GetModuleStateWhenEffectApplied(0) )
            {
                case EFFECT_ONLINE:
                    m_OnlineEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                case EFFECT_ACTIVE:
                    m_ActiveEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                case EFFECT_OVERLOAD:
                    m_OverloadEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
                    break;
                default:
                    sLog.Error("ModuleEffects::_populate()", "Illegal value '%u' obtained from the 'effectAppliedInState' field of the 'dgmEffectsInfo' table", mEffectPtr->GetModuleStateWhenEffectApplied(0));
                    break;
            }
        }
    }

    //cleanup
    delete res;
    res = NULL;

}
Example #27
0
//this is a crap load of work... there HAS to be a better way to do this..
PyObject *MarketDB::GetMarketGroups() {
	DBQueryResult res;

	//returns cached object marketProxy.GetMarketGroups
	//marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes, types
	//this is going to be a real pain... another "nested" query thing...
	// I really wanna know how they do this crap with their MS SQL server.. 
	// I hope its not as much of a nightmare as it is for us....

	//first we need to query out all the types because we need them to 
	// fill in the 'types' subquery for each row of the result
	std::map< int, std::set<uint32> > types;	//maps marketGroupID -> typeID
	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID,typeID"
		" FROM invTypes"
		" WHERE marketGroupID IS NOT NULL"
		" ORDER BY marketGroupID"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}
	
	DBResultRow row;
	while(res.GetRow(row))
		types[row.GetUInt(0)].insert(row.GetUInt(1));

	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID, parentGroupID"
		" FROM invMarketGroups"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}

	std::map<int, int> parentChild;	//maps child -> parent
	std::map<int, std::set<int> > childParent; //maps parent -> all children.
	while(res.GetRow(row)) {
		//figure out the parent ID, mapping NULL to -1 for our map.
		int marketGroupID = row.GetUInt(0);
		int parentGroupID = row.IsNull(1) ? -1 : row.GetUInt(1);

		parentChild[marketGroupID] = parentGroupID;
		childParent[parentGroupID].insert(marketGroupID);
	}

	//now we need to propigate all of the items up the tree (a parent group's items list contains ALL items of its children.)
	_PropigateItems(types, parentChild, childParent, -1);

	//now we get to do the other query.
	if(!sDatabase.RunQuery(res,
		"SELECT"
		"	marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes"
		" FROM invMarketGroups"))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}

	//doing this the long (non XML) way to avoid the extra copies due to the huge volume of data here.
	PyDict *args = new PyDict();

	PyDict *parentSets = new PyDict();
	PyList *header = new PyList();
	
	header->AddItemString("marketGroupID");
	header->AddItemString("parentGroupID");
	header->AddItemString("marketGroupName");
	header->AddItemString("description");
	header->AddItemString("graphicID");
	header->AddItemString("hasTypes");
	header->AddItemString("types");	//this column really contains an entire list.
	header->AddItemString("dataID");
	
	args->SetItemString("header", header);
	args->SetItemString("idName", new PyString("parentGroupID"));
	args->SetItemString("RowClass", new PyToken("util.Row"));
	args->SetItemString("idName2", new PyNone);
	args->SetItemString("items", parentSets);
	
	//now fill in items.
	// we have to satisfy this structure... which uses parentGroupID as the
	// main dict key, each dict entry is then a list of MarketGroup_Entrys
	// which have that parentGroupID
	//marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes, types
	std::map< int, std::set<uint32> >::const_iterator tt;
	MarketGroup_Entry entry;
    PyList* list;
    PyList* parents = new PyList();
	while( res.GetRow(row) )
	{
		entry.marketGroupID = row.GetUInt( 0 );

		//figure out the parent ID, mapping NULL to -1 for our map.
		entry.parentGroupID = ( row.IsNull( 1 ) ? -1 : row.GetUInt( 1 ) );

		entry.marketGroupName = row.GetText( 2 );
		entry.description = row.GetText( 3 );
		entry.graphicID = ( row.IsNull( 4 ) ? -1 : row.GetUInt( 4 ) );		
		entry.hasTypes = row.GetUInt( 5 );

		// Insert all types
		entry.types.clear();
		tt = types.find( entry.marketGroupID );
		if( tt != types.end() )
			entry.types.insert( entry.types.begin(), tt->second.begin(), tt->second.end() );

        if(entry.parentGroupID == -1)
			list = parents;
		else
			list = static_cast<PyList*> (parentSets->GetItem(new PyInt( entry.parentGroupID )));
        if(list == NULL)
            list = new PyList();
        list->AddItem(entry.Encode());
        PySafeIncRef(list);
        if(entry.parentGroupID != -1)
			parentSets->SetItem(new PyInt(entry.parentGroupID), list);
	}
    parentSets->SetItem(new PyNone, parents);

	return new PyObject( "util.FilterRowset", args );
}
Example #28
0
void FillPackedRow( const DBResultRow& row, PyPackedRow* into )
{
    uint32 cc = row.ColumnCount();
    for( uint32 i = 0; i < cc; i++ )
        into->SetField( i, DBColumnToPyRep( row, i ) );
}
Example #29
0
PyRep *SearchDB::QuickQuery(std::string match, std::vector<int> *SearchID) {
    DBQueryResult     res; 
    DBResultRow       row;
    uint32            i, size;
    std::stringstream st;
    std::stringstream supplement;
    std::string       query      = "";
    std::string       equal      = "";
    std::string       matchEsc   = "";

    //SearchIDs are :
    // 1 : agent
    // 2 : character
    // 3 : corporation
    // 4 : alliance
    // 5 : faction
    // 6 : constellation
    // 7 : solar system
    // 8 : region
    // 9 : station

    // Find out if search is exact or not and remove the trailing '*'
    std::size_t found=match.find('*');
    if (found!=std::string::npos) {
      match.erase (std::remove(match.begin(), match.end(), '*'), match.end());
      equal = " RLIKE ";
    } else {
      equal = " = ";
    }


    // If the SearchID is for character we must filter out agents
    size = SearchID->size();
    if ((size == 1) && (SearchID->at(0)) == 2){
        supplement << "AND itemId >= ";
        supplement << EVEMU_MINIMUM_ID;
    }

    // Transform SearchId in groupID to search the rights typeIDs
    int transform[9] = {1,1,2,32,19,4,5,3,15};
    for(i=0; i<size; i++)
    {
        st << transform[SearchID->at(i)-1];
        if (i<(size-1))
            st << ", ";
    }
    
    // Escape the match string
    sDatabase.DoEscapeString(matchEsc, match.c_str());

    //Form the query and execute it
    query = "SELECT itemID,itemName FROM entity"
            " WHERE itemName RLIKE '%s' %s"
            " AND typeID in (SELECT typeID FROM invTypes LEFT JOIN invGroups ON invTypes.groupid = invGroups.groupID"
            " WHERE invGroups.groupID IN (%s))"
            " ORDER BY itemName";


    _log(SERVICE__MESSAGE, query.c_str(), matchEsc.c_str(), supplement.str().c_str() ,st.str().c_str());

    if(!sDatabase.RunQuery(res,query.c_str(), matchEsc.c_str(), supplement.str().c_str() , st.str().c_str() ))
    {
        _log(SERVICE__ERROR, "Error in LookupChars query: %s", res.error.c_str());
        return NULL;
    }

    // The cliant wants a List if Ids in return
    PyList *result = new PyList();
    while( res.GetRow( row ) ){
        result->AddItem( new PyInt(row.GetUInt(0) ));
    }

    return result;


}
Example #30
0
// Function: Query the 'channelChars' table for all channels subscribed to by the character specified by charID and
// return lists of parameters for all of those channels as well as a total channel count.
void LSCDB::GetChannelSubscriptions(uint32 charID, std::vector<unsigned long> & ids, std::vector<std::string> & names,
		std::vector<std::string> & MOTDs, std::vector<unsigned long> & ownerids, std::vector<std::string> & compkeys,
		std::vector<int> & memberless, std::vector<std::string> & passwords, std::vector<int> & maillists,
		std::vector<int> & cspas, std::vector<int> & temps, std::vector<int> & modes, int & channelCount)
{
	DBQueryResult res;

	// Cross-reference "channelchars" table with "channels" table using the charID
	// The result is a two column multi-row structure where each row is a channel
	// that the character (charID) is subscribed to where the channel ID is presented
	// in the first column and the display name of that channel in the second column
	if (!sDatabase.RunQuery(res,
		" SELECT "
		"	channelID, "
		"	displayName, "
		"   motd, "
		"   ownerID, "
		"   comparisonKey, "
		"   memberless, "
		"   password, "
		"   mailingList, "
		"   cspa, "
		"   temporary, "
		"   mode "
		" FROM channels "
		" WHERE channelID = ANY ("
		"   SELECT channelID FROM channelChars WHERE charID = %u )", charID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return;
	}

	DBResultRow row;
	int rowCount = 0;

	// Traverse through all rows in the query result and copy the IDs and displayNames to the
	// "ids" and "names" vectors for return to the calling function:
	while(res.GetRow(row))
	{
		++rowCount;

		ids.push_back(row.GetUInt(0));
		names.push_back((row.GetText(1) == NULL ? "" : row.GetText(1)));	// empty displayName field in channels table row returns NULL, so fill this string with "" in that case
		MOTDs.push_back((row.GetText(2) == NULL ? "" : row.GetText(2)));	// empty motd field in channels table row returns NULL, so fill this string with "" in that case
		ownerids.push_back(row.GetUInt(3));
		compkeys.push_back((row.GetText(4) == NULL ? "" : row.GetText(4)));	// empty comparisonKey field in channels table row returns NULL, so fill this string with "" in that case
		memberless.push_back(row.GetUInt(5));
		passwords.push_back((row.GetText(6) == NULL ? "" : row.GetText(6)));	// empty password field in channels table row returns NULL, so fill this string with "" in that case
		maillists.push_back(row.GetUInt(7));
		cspas.push_back(row.GetUInt(8));
		temps.push_back(row.GetUInt(9));
		modes.push_back(row.GetUInt(10));
	}

	if (rowCount == 0) {
		_log(SERVICE__ERROR, "CharID %u isn't present in the database", charID);
		return;
	}

	channelCount = rowCount;
}