PyTuple *DBResultToRowList(DBQueryResult &result, const char *type) { uint32 cc = result.ColumnCount(); if(cc == 0) return(new PyTuple(0)); uint32 r; PyTuple *res = new PyTuple(2); PyList *cols = new PyList(cc); PyList *reslist = new PyList(); res->SetItem( 0, cols ); res->SetItem( 1, reslist ); //list off the column names: for(r = 0; r < cc; r++) { cols->SetItemString(r, result.ColumnName(r)); } //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { //this could be more efficient by not building the column list each time, but cloning it instead. PyObject *o = DBRowToRow(row, type); reslist->items.push_back(o); } return res; }
PyObject *CorporationDB::GetCorporation(uint32 corpID) { 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", corpID)) { codelog(SERVICE__ERROR, "Error in retrieving corporation's data (%u)", corpID); return NULL; } if(!res.GetRow(row)) { codelog(SERVICE__ERROR, "Unable to find corporation's data (%u)", corpID); return NULL; } return DBRowToRow(row); //return DBResultToRowset(res); }
PyObject *ServiceDB::GetSolRow(uint32 systemID) { DBQueryResult res; if(!DBcore::RunQuery(res, //not sure if this is gunna be valid all the time... "SELECT " " itemID,srvEntity.typeID,ownerID,locationID,flag,contraband,singleton,quantity," " invGroups.groupID, invGroups.categoryID," " customInfo" " FROM srvEntity " " LEFT JOIN invTypes ON srvEntity.typeID=invTypes.typeID" " LEFT JOIN invGroups ON invTypes.groupID=invGroups.groupID" " WHERE srvEntity.itemID=%u", systemID )) { _log(SERVICE__ERROR, "Error in GetSolRow query: %s", res.error.c_str()); return(0); } DBResultRow row; if(!res.GetRow(row)) { _log(SERVICE__ERROR, "Error in GetSolRow query: unable to find sol info for system %d", systemID); return(0); } return(DBRowToRow(row, "util.Row")); }
PyDict *DBResultToIntRowDict(DBQueryResult &result, uint32 key_index, const char *type) { PyDict *res = new PyDict(); //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { //this could be more efficient by not building the column list each time, but cloning it instead. PyObject *r = DBRowToRow(row, type); int32 k = row.GetInt(key_index); if(k == 0) continue; //likely a non-integer key res->SetItem(new PyInt(k), r); } return res; }
PyRep* PaperDollDB::GetPaperDollAvatar(uint32 charID) { DBQueryResult res; if (!DBcore::RunQuery(res, " (SELECT hairDarkness FROM avatars WHERE `charID`=%u ) ", charID)) { _log(DATABASE__ERROR, "Error in GetMyPaperDollData query: %s", res.error.c_str()); return (NULL); } DBResultRow row; res.GetRow(row); return DBRowToRow(row, "util.Row"); }