Beispiel #1
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));

}
Beispiel #2
0
//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;
}
//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;
}
Beispiel #4
0
// Function: Return true or false result for the check of whether or not the specified
// channelID is available to be taken for a new channel's channelID.
bool LSCDB::IsChannelIDAvailable(uint32 channelID)
{
    DBQueryResult res;

    if (!sDatabase.RunQuery(res,
        " SELECT "
        "    channelID "
        " FROM channels "
        " WHERE channelID = %u", channelID ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return false;
    }

    DBResultRow row;

    // Return true (this channelID not in use) if there are no rows returned by the query:
    if (!(res.GetRow(row)))
        return true;
    else
        return false;
}
Beispiel #5
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;
}
PyObject *CharacterDB::GetCharPublicInfo(uint32 characterID) {
	DBQueryResult res;

	if(!sDatabase.RunQuery(res,
		"SELECT "
		" entity.typeID,"
		" character_.corporationID,"
        " chrBloodlines.raceID,"
		" bloodlineTypes.bloodlineID,"
		" character_.ancestryID,"
		" character_.careerID,"
		" character_.schoolID,"
		" character_.careerSpecialityID,"
		" entity.itemName AS characterName,"
		" 0 as age,"	//hack
		" character_.createDateTime,"
		" character_.gender,"
		" character_.characterID,"
		" character_.description,"
		" character_.corporationDateTime"
        " FROM character_ "
		"	LEFT JOIN entity ON characterID = itemID"
		"	LEFT JOIN bloodlineTypes USING (typeID)"
		"	LEFT JOIN chrBloodlines USING (bloodlineID)"
		" WHERE characterID=%u", characterID))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return NULL;
	}
	
	DBResultRow row;
	if(!res.GetRow(row)) {
		_log(SERVICE__ERROR, "Error in GetCharPublicInfo query: no data for char %d", characterID);
		return NULL;
	}
	return(DBRowToKeyVal(row));
	
}
/**
  * @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);
}
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);
}
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;
}
Beispiel #10
0
PyRep *MarketDB::GetOrderRow(uint32 orderID) {
    DBQueryResult res;

    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    price, volRemaining, typeID, `range`, orderID,"
        "   volEntered, minVolume, bid, issued as issueDate, duration,"
        "   stationID, regionID, solarSystemID, jumps"
        " FROM market_orders"
        " WHERE orderID=%u", orderID))
    {
        codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
        return NULL;
    }

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

    return(DBRowToPackedRow(row));
}
Beispiel #11
0
// Function: Return true or false result for the check of whether or not the channel
// specified by channelID is already subscribed to by the character specified by charID.
bool LSCDB::IsChannelSubscribedByThisChar(uint32 charID, uint32 channelID)
{
	DBQueryResult res;

	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	channelID, "
		"   charID "
		" FROM channelChars "
		" WHERE channelID = %u AND charID = %u", channelID, charID ))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return false;
	}

	DBResultRow row;

    // Return false (no subscription exists) if there are no rows returned by the query:
	if (!(res.GetRow(row)))
		return false;
	else
		return true;
}
Beispiel #12
0
// Function: Return true or false result for the check of whether or not the specified
// channel 'displayName' is already being used by a channel.
bool LSCDB::IsChannelNameAvailable(std::string name)
{
	DBQueryResult res;

	// MySQL query channels table for any channel whose displayName matches "name":
	if (!sDatabase.RunQuery(res, 
		" SELECT "
		"	displayName "
		" FROM channels "
		" WHERE displayName = upper('%s')", name.c_str()))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
		return false;
	}

	DBResultRow row;

    // Return true (this 'displayName' not in use) if there are no rows returned by the query:
	if (!res.GetRow(row))
		return true;
	else
		return false;
}
Beispiel #13
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;
}
Beispiel #14
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;
}
Beispiel #15
0
    Bool TroopDBOp::checkOrCreateTroopTable( DBDriver& driver )
    {
        static Colume troopColumn[] = 
        {      		
            {"troop_master_id",			"BIGINT",			"0"},				//根据以上主人类型,记录的Id( 或regionID或clanID )
            {"troop_template_id",		"INT",		        "0"},				//军队模板id	
            {"troop_master_type",	    "INT",		        "0"},				//"军队主人的类型,   
            {"troop_life_type",			"INT",		        "0"},				//军队存活类型,
            {"troop_lvl",               "INT",              "0"},               //军队等级
            {"troop_exp",			    "INT",			    "0"},				//军队当前经验度,最大为1000
            {"troop_num",		        "INT",			    "0"},				//军队当前兵数		
            {"troop_loyal",		        "INT",			    "0"},				//军队当前忠诚度,最大为1000
            {"troop_weapon",			"INT",			    "0"},				//军队当前武装度,最大为1000           
            {"troop_wound",			    "INT",			    "0"},				//军队当前伤兵率,最大为1000            
        };

        DBQueryResultEx resEx = driver.query("CREATE TABLE IF NOT EXISTS "TROOP_TABLE_NAME" (troop_id BIGINT NOT NULL AUTO_INCREMENT,PRIMARY KEY(troop_id))");
        DBQueryResult* pRes = *resEx;
        if (!pRes ||(pRes && pRes->getResultType() == DBQuery_Result_INVALID))
        {
            return false;
        }

        Bool res1 = driver.addColume(TROOP_TABLE_NAME,troopColumn,sizeof(troopColumn)/sizeof(Colume));
        if (!res1)
        {
            return false;
        }
        //加索引
        if ( !( *( driver.query("ALTER TABLE "TROOP_TABLE_NAME" ADD INDEX  troopmaster (troop_master_id, troop_master_type)") ) ) )
        {
            return false;
        }

        return true;
    }
Beispiel #16
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;
}
Beispiel #17
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;
}
Beispiel #18
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)
}
Beispiel #19
0
void DBResultToUIntUIntDict(DBQueryResult &result, std::map<uint32, uint32> &into) {
    //add a line entry for each result row:
    DBResultRow row;
    while(result.GetRow(row)) {
        if(row.IsNull(0))
            continue;   //no working with NULL keys...
        uint32 k = row.GetUInt(0);
        int32 v;
        if(row.IsNull(1))
            v = 0;      //we can deal with assuming NULL == 0
        else
            v = row.GetInt(1);
        into[k] = v;
    }
}
Beispiel #20
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);
	}
	
}
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;

}
Beispiel #22
0
    //-------------------------------------------------------------------------------------------
    MG::Bool ItemDBOp::getItemDB( DBDriver& driver, const U64& clanID, const ITEM_BELONG_TYPE& type, std::vector<ItemRecord>& recordList )
    {
        ItemRecord data;

        Char8 sql[128] = {0};
        MGStrOp::sprintf(sql,128,"select * from "ITEMDB_TABLE_NAME" where itemdb_belong_id = %I64d and itemdb_belong_type = %d",clanID, type);

        DBQueryResultEx resEx = driver.query(sql);
        DBQueryResult* res = *resEx;
        if ( res  &&  res->getResultType() != DBQuery_Result_INVALID  &&  res->getRowCount() > 0 )
        {
            Str16 wName;
            Str   tempStr;

            I32 nRow = res->getRowCount();
            for ( I32 i=0; i<nRow; i++ )
            {
                memset(&data, 0, sizeof(data));
                U32 nCol = 0;
                
                
               // data.itemDBID                    = res->getFieldData( i, nCol++ )->ulonglongData;
                data.characterId                 = res->getFieldData( i, nCol++ )->ulonglongData;
                data.itemTempID                  = res->getFieldData( i, nCol++ )->uintData;
                data.itemBelongID                = res->getFieldData( i, nCol++ )->ulonglongData;
                data.itemBelongType              = (ITEM_BELONG_TYPE)( res->getFieldData( i, nCol++ )->ubyteData );
                data.belongPos                   = (ITEM_SITE_TYPE)( res->getFieldData( i, nCol++ )->ubyteData );
                data.slotIndex                       = res->getFieldData( i, nCol++ )->uintData;
                res->getFieldData(i, nCol++, tempStr);
                MGStrOp::toString(tempStr.c_str(), wName);
                memcpy(data.fatherName, wName.c_str(), sizeof(MAX_CHARACTER_NAME_LEN));
                data.bindType                    = (ITEM_BIND_TYPE)( res->getFieldData( i, nCol++ )->ubyteData );
                data.curNum                      = res->getFieldData( i, nCol++ )->uintData;
                data.curDurable                  = res->getFieldData( i, nCol++ )->uintData;
                data.curRepairNum                = res->getFieldData( i, nCol++ )->uintData;
                data.curStrengthenLv             = res->getFieldData( i, nCol++ )->uintData;
                data.randAppendID                = res->getFieldData( i, nCol++ )->uintData;
                data.strengthenAppendID          = res->getFieldData( i, nCol++ )->uintData;
                //时间
                /*data.dueTime                     = res->getFieldData( i, nCol++ )->ulonglongData;
                data.bornTime                    = res->getFieldData( i, nCol++ )->ulonglongData;
                data.delTime                     = res->getFieldData( i, nCol++ )->ulonglongData;
                data.updateTime                  = res->getFieldData( i, nCol++ )->ulonglongData;*/
                

                recordList.push_back(data);
            }
            return true;
        }

        return false;
    }
Beispiel #23
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 );
}
Beispiel #24
0
PyRep *MarketDB::GetOrders( uint32 regionID, uint32 typeID )
{
    DBQueryResult res;

    PyList* tup = new PyList();

    /*DBColumnTypeMap colmap;
    colmap["volRemaining"] = DBTYPE_R8;
    colmap["price"] = DBTYPE_CY;
    colmap["issued"] = DBTYPE_FILETIME;

    colmap["orderID"] = DBTYPE_I4;
    colmap["volEntered"] = DBTYPE_I4;
    colmap["minVolume"] = DBTYPE_I4;
    colmap["stationID"] = DBTYPE_I4;
    colmap["regionID"] = DBTYPE_I4;
    colmap["solarSystemID"] = DBTYPE_I4;
    colmap["jumps"] = DBTYPE_I4;

    colmap["duration"] = DBTYPE_I2;
    colmap["typeID"] = DBTYPE_I2;
    colmap["range"] = DBTYPE_I2;

    colmap["bid"] = DBTYPE_BOOL;

    //ordering: (painstakingly determined from packets)
    DBColumnOrdering ordering;
    ordering.push_back("price");
    ordering.push_back("volRemaining");
    ordering.push_back("issued");
    ordering.push_back("orderID");
    ordering.push_back("volEntered");
    ordering.push_back("minVolume");
    ordering.push_back("stationID");
    ordering.push_back("regionID");
    ordering.push_back("solarSystemID");
    ordering.push_back("jumps");    //not working right...
    ordering.push_back("typeID");
    ordering.push_back("range");
    ordering.push_back("duration");
    ordering.push_back("bid");*/

    //query sell orders
    //TODO: consider the `jumps` field... is it actually used? might be a pain in the ass if we need to actually populate it based on each queryier's location
    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    price, volRemaining, typeID, `range`, orderID,"
        "   volEntered, minVolume, bid, issued as issueDate, duration,"
        "   stationID, regionID, solarSystemID, jumps"
        " FROM market_orders "
        " WHERE regionID=%u AND typeID=%u AND bid=%d", regionID, typeID, TransactionTypeSell))
    {
        codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );

        PyDecRef( tup );
        return NULL;
    }
    sLog.Debug("MarketDB::GetOrders", "Fetched %d sell orders for type %d", res.GetRowCount(), typeID);

    //this is wrong.
    tup->AddItem( DBResultToCRowset( res ) );

    //query buy orders
    if(!sDatabase.RunQuery(res,
        "SELECT"
        "    price, volRemaining, typeID, `range`, orderID,"
        "   volEntered, minVolume, bid, issued as issueDate, duration,"
        "   stationID, regionID, solarSystemID, jumps"
        " FROM market_orders "
        " WHERE regionID=%u AND typeID=%u AND bid=%d", regionID, typeID, TransactionTypeBuy))
    {
        codelog( MARKET__ERROR, "Error in query: %s", res.error.c_str() );

        PyDecRef( tup );
        return NULL;
    }
    sLog.Debug("MarketDB::GetOrders", "Fetched %d buy orders for type %d", res.GetRowCount(), typeID);

    //this is wrong.
    tup->AddItem( DBResultToCRowset( res ) );

    return tup;
}
Beispiel #25
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;
}
Beispiel #26
0
PyRep *SearchDB::Query(std::string match,  std::vector<int> *searchID) {

    DBQueryResult res;
    DBResultRow   row;
    std::string   id;
    uint32        i,size;
    std::string   equal    = "";
    std::string   matchEsc = "";

    // 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 = " = ";
    }

    // Escape the searchString
    sDatabase.DoEscapeString(matchEsc, match.c_str());


    // The client wants a dict in return
    // [searchID][Results]

    PyDict *dict = new PyDict();
    size = searchID->size();

    for(i=0; i<size; i++){

	switch(searchID->at(i)) {
	  case 1:	//searchResultAgent = 1
            sDatabase.RunQuery(res,
	    "SELECT"
            " itemID AS agentID"
            " FROM entity"
            " WHERE itemName %s '%s' "
            " AND itemID BETWEEN 2999999 AND 4000000 "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 2:	//searchResultCharacter = 2
            sDatabase.RunQuery(res,
	    "SELECT"
            " itemID"
            " FROM entity"
            " WHERE itemName %s '%s' "
            " AND itemId >= %u"
            " AND ownerID = 1",equal.c_str(), matchEsc.c_str(),EVEMU_MINIMUM_ID );
            break;
	  case 3:	//searchResultCorporation = 3
            sDatabase.RunQuery(res,
	    "SELECT"
            " corporationID"
            " FROM corporation"
            " WHERE corporationName %s '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 4:	//searchResultAlliance = 4
            sDatabase.RunQuery(res,
	    "SELECT allianceID"
            " FROM alliance_ShortNames"
            " WHERE shortName %s '%s'"
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str()  );
            break;
	  case 5:	//searchResultFaction = 5
            sDatabase.RunQuery(res,
	    "SELECT factionID"
            " FROM chrFactions"
            " WHERE factionName %S '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 6:	//searchResultConstellation = 6
            sDatabase.RunQuery(res,
	    "SELECT"
            " constellationID"
            " FROM mapConstellations"
            " WHERE constellationName %s '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
          
	  case 7:	//searchResultSolarSystem = 7
            sDatabase.RunQuery(res,
	    "SELECT "
            " solarSystemID"
            " FROM mapSolarSystems"
            " WHERE solarSystemName %s '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 8:	//searchResultRegion = 8
            sDatabase.RunQuery(res,
      	    "SELECT "
            " regionID"
            " FROM mapRegions"
            " WHERE regionName %s '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 9:	//searchResultStation = 9
            sDatabase.RunQuery(res,
	    "SELECT "
            " stationID"
            " FROM staStations "
            " WHERE stationName %s '%s' "
            " LIMIT 0, 10", equal.c_str(), matchEsc.c_str() );
            break;
	  case 10:	//searchResultInventoryType = 10
	    sDatabase.RunQuery(res,
	    "SELECT"
            "   typeID"
            " FROM entity"
            " WHERE itemName %s '%s'", equal.c_str(), matchEsc.c_str() );
            break;
	}

	dict->SetItem(new PyInt(searchID->at(i)),DBResultToIntIntDict(res));
        res.Reset();
    }

    return dict;
}
Beispiel #27
0
// this one needs some love
//int henk = "bla";
PyRep *StationDB::DoGetStation(uint32 sid)
{
	DBQueryResult res;

//" SELECT staStations.stationID, staStations.security, staStations.dockingCostPerVolume, staStations.maxShipVolumeDockable, staStations.officeRentalCost, staStations.operationID, staStations.stationTypeID, staStations.corporationID AS ownerID, staStations.solarSystemID, staStations.constellationID, staStations.regionID, staStations.stationName, staStations.x, staStations.y, staStations.z, staStations.reprocessingEfficiency, staStations.reprocessingStationsTake, staStations.reprocessingHangarFlag, staOperations.description, CAST(SUM(staOperationServices.serviceID) as UNSIGNED INTEGER) AS serviceMask FROM staStations LEFT JOIN staOperations ON staStations.operationID = staOperations.operationID LEFT JOIN staOperationServices ON staStations.operationID = staOperationServices.operationID WHERE staStations.stationID = %u GROUP BY staStations.stationID 

    if(!sDatabase.RunQuery(res, "SELECT"
    "staStations.x,"
    "staStations.y,"
    "staStations.z,"
    "mapDenormalize.orbitID,"
    "staStationTypes.hangarGraphicID,"
    "staStations.stationID,"
    "0 AS upgradelevel,"
    "invtypes.graphicID,"
    "staStations.regionID,"
    "staStations.security,"
    "staStations.stationTypeID,"
    "staStationTypes.dockingBayGraphicID,"
    "staStations.officeRentalCost,"
    "staStations.stationName,"
    "staOperations.description,"
    "staStations.constellationID,"
    "staStations.operationID,"
    "staStations.solarSystemID,"
    "staStationTypes.dockOrientationX,"
    "staStationTypes.dockOrientationY,"
    "staStationTypes.dockOrientationZ,"
    "staStations.corporationID AS standingOwnerID,"
    //"58012245 AS serviceMask,"
    "CAST(SUM(staOperationServices.serviceID) as UNSIGNED INTEGER) AS serviceMask "
    "staStations.dockingCostPerVolume,"
    "staStations.reprocessingHangarFlag,"
    "staStations.reprocessingEfficiency,"
    "staStationTypes.dockEntryX,"
    "staStationTypes.dockEntryY,"
    "staStationTypes.dockEntryZ,"
    "staStations.maxShipVolumeDockable,"
    "staStations.corporationID AS ownerID,"
    "staStationTypes.conquerable,"
    "mapDenormalize.radius"
    "from staStations "
    "LEFT JOIN staStationTypes ON "
    "staStations.stationTypeID=staStationTypes.stationTypeID "
    "LEFT JOIN mapDenormalize ON "
    "staStations.stationID=mapDenormalize.itemID "
    "LEFT JOIN invtypes ON "
    "staStations.stationTypeID=invtypes.typeID "
    "LEFT JOIN staOperations ON "
    "staStations.operationID=staOperations.operationID "
    "LEFT JOIN staOperationServices ON "
    "staStations.operationID=staOperationServices.operationID "
    "WHERE staStations.stationID = %u GROUP BY staStations.stationID", sid ))
    {
        //_log(SERVICE__ERROR, "Error in DoGetStation query: %s", res.error.c_str());
        sLog.Error("StationDB", "Error in DoGetStation query: %s", res.error.c_str());
        return NULL;
    }

	/*if(!sDatabase.RunQuery(res,
		" SELECT "
		" staStations.stationID, staStations.security, staStations.dockingCostPerVolume, staStations.maxShipVolumeDockable, "
		" staStations.officeRentalCost, staStations.operationID, staStations.stationTypeID, staStations.corporationID AS ownerID, staStations.solarSystemID, staStations.constellationID, "
		" staStations.regionID, staStations.stationName, staStations.x, staStations.y, staStations.z, staStations.reprocessingEfficiency, staStations.reprocessingStationsTake, staStations.reprocessingHangarFlag, "
		" staOperations.description, "
		// 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 staOperations ON staStations.operationID = staOperations.operationID "
		" LEFT JOIN staOperationServices ON staStations.operationID = staOperationServices.operationID "
		" WHERE staStations.stationID = %u "
		" GROUP BY staStations.stationID ", sid
	))
    
	{
		_log(SERVICE__ERROR, "Error in DoGetStation query: %s", res.error.c_str());
		return NULL;
	}*/

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

	//only a guess that this is row
	return DBRowToKeyVal(row);
}
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;
}
Beispiel #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;


}
void MEffect::_Populate(uint32 effectID)
{
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetDgmEffects(effectID, *res);

    // First, get all general info on this effectID from the dgmEffects table:
    DBResultRow row1;
    if( !res->GetRow(row1) )
        sLog.Error("MEffect","Could not populate effect information for effectID: %u from the 'dgmEffects' table", effectID);
    else
    {
        //get all the data from the query
        m_EffectID = effectID;
        m_EffectName = row1.GetText(0);
        m_EffectCategory = row1.GetInt(1);
        m_PreExpression = row1.GetInt(2);
        m_PostExpression = row1.GetInt(3);
        if( !row1.IsNull(4) )
            m_Description = row1.GetText(4);
        if( !row1.IsNull(5) )
            m_Guid = row1.GetText(5);
        if( !row1.IsNull(6) )
            m_IconID = row1.GetInt(6);
        m_IsOffensive = row1.GetInt(7);
        m_IsAssistance = row1.GetInt(8);
        if( !row1.IsNull(9) )
            m_DurationAttributeID = row1.GetInt(9);
        if( !row1.IsNull(10) )
            m_TrackingSpeedAttributeID = row1.GetInt(10);
        if( !row1.IsNull(11) )
            m_DischargeAttributeID = row1.GetInt(11);
        if( !row1.IsNull(12) )
            m_RangeAttributeID = row1.GetInt(12);
        if( !row1.IsNull(13) )
            m_FalloffAttributeID = row1.GetInt(13);
        if( !row1.IsNull(14) )
            m_DisallowAutoRepeat = row1.GetInt(14);
        m_Published = row1.GetInt(15);
        if( !row1.IsNull(16) )
            m_DisplayName = row1.GetText(16);
        m_IsWarpSafe = row1.GetInt(17);
        m_RangeChance = row1.GetInt(18);
        m_ElectronicChance = row1.GetInt(19);
        m_PropulsionChance = row1.GetInt(20);
        if( !row1.IsNull(21) )
            m_Distribution = row1.GetInt(21);
        if( !row1.IsNull(22) )
            m_SfxName = row1.GetText(22);
        if( !row1.IsNull(23) )
            m_NpcUsageChanceAttributeID = row1.GetInt(23);
        if( !row1.IsNull(24) )
            m_NpcActivationChanceAttributeID = row1.GetInt(24);
        if( !row1.IsNull(25) )
            m_FittingUsageChanceAttributeID = row1.GetInt(25);
    }

    // Next, get the info from the dgmEffectsInfo table:
    ModuleDB::GetDgmEffectsInfo(effectID, *res);

    DBResultRow row2;

    // Initialize the new tables
    m_TargetAttributeIDs = new int[res->GetRowCount()];
    m_SourceAttributeIDs = new int[res->GetRowCount()];
    m_CalculationTypeIDs = new int[res->GetRowCount()];
    m_ReverseCalculationTypeIDs = new int[res->GetRowCount()];

    int count = 0;

    while( res->GetRow(row2) )
    {
        m_TargetAttributeIDs[count] = row2.GetInt(0);
        m_SourceAttributeIDs[count] = row2.GetInt(1);
        m_CalculationTypeIDs[count] = row2.GetInt(2);
        m_ReverseCalculationTypeIDs[count] = row2.GetInt(3);
        count++;
    }

    if( count == 0 )
        sLog.Error("MEffect","Could not populate effect information for effectID: %u from the 'dgmEffectsInfo' table as the SQL query returned ZERO rows", effectID);

    m_numOfIDs = count;

    // Finally, get the info for this effectID from the dgmEffectsActions table:
    ModuleDB::GetDgmEffectsActions(effectID, *res);

    DBResultRow row3;

    if( !(res->GetRow(row3)) )
        sLog.Error("MEffect","Could not populate effect information for effectID: %u from 'dgmEffectsActions table", effectID);
    else
    {
        m_EffectAppliedWhenID = row3.GetInt(0);
        m_EffectAppliedTargetID = row3.GetInt(1);
        m_EffectApplicationTypeID = row3.GetInt(2);
        m_StackingPenaltyAppliedID = row3.GetInt(3);
        m_NullifyOnlineEffectEnable = row3.GetInt(4);
        m_NullifiedOnlineEffectID = row3.GetInt(5);
    }

    delete res;
    res = NULL;
}