Shadowrun: Awakened 29 September 2011 - Build 871
DbProcedures.cpp
Go to the documentation of this file.
00001 // TestDLL.cpp : Defines the exported functions for the DLL application.
00002 
00003 #include "stdafx.h"
00004 
00005 #include <stdint.h>
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <iostream>
00009 #include <map>
00010 #include <memory>
00011 
00012 #include <cppconn/driver.h>
00013 #include <cppconn/exception.h>
00014 #include <cppconn/resultset.h>
00015 #include <cppconn/statement.h>
00016 #include <cppconn/prepared_statement.h>
00017 
00018 #include "DbConnectionFactory.h"
00019 #include "DbProcedures.h"
00020 #include "DbStream.h"
00021 
00022 //http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-stored-routines-statements.html
00023 
00024 namespace SraData
00025 {
00026     void DbProcedures::clearCharQuality(int pInCharId, int pInQualityId)
00027     {
00028         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00029         std::auto_ptr<sql::PreparedStatement> pstmt;
00030         pstmt.reset(connection->prepareStatement("CALL clear_char_quality(?,?)"));
00031         pstmt->setInt(1,pInCharId);
00032         pstmt->setInt(2,pInQualityId);
00033             
00034         pstmt->execute();
00035             
00036         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00037     }
00038         
00039     void DbProcedures::clearCharSpell(int pInCharId, int pInSpellId)
00040     {
00041         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00042         std::auto_ptr<sql::PreparedStatement> pstmt;
00043         pstmt.reset(connection->prepareStatement("CALL clear_char_spell(?,?)"));
00044         pstmt->setInt(1,pInCharId);
00045         pstmt->setInt(2,pInSpellId);
00046             
00047         pstmt->execute();
00048             
00049         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00050     }
00051         
00052     void DbProcedures::createCharacter(int pInRaceId, int* pOutId)
00053     {
00054         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00055         std::auto_ptr<sql::PreparedStatement> pstmt;
00056         pstmt.reset(connection->prepareStatement("CALL create_character(?,@param1)"));
00057         pstmt->setInt(1,pInRaceId);
00058             
00059         pstmt->execute();
00060             
00061         {
00062             std::auto_ptr< sql::ResultSet > res;
00063             std::auto_ptr< sql::Statement > stmt;
00064             stmt.reset(connection->createStatement());
00065             res.reset(stmt->executeQuery("SELECT @param1 from dual"));
00066             res->next();
00067             *pOutId = res->getInt(1);
00068         }
00069             
00070         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00071     }
00072         
00073     void DbProcedures::createGearItem(int pInGearId, int pInOwnerCharId, int pInRating, int* pOutGearItemId)
00074     {
00075         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00076         std::auto_ptr<sql::PreparedStatement> pstmt;
00077         pstmt.reset(connection->prepareStatement("CALL create_gear_item(?,?,?,@param3)"));
00078         pstmt->setInt(1,pInGearId);
00079         pstmt->setInt(2,pInOwnerCharId);
00080         pstmt->setInt(3,pInRating);
00081             
00082         pstmt->execute();
00083             
00084         {
00085             std::auto_ptr< sql::ResultSet > res;
00086             std::auto_ptr< sql::Statement > stmt;
00087             stmt.reset(connection->createStatement());
00088             res.reset(stmt->executeQuery("SELECT @param3 from dual"));
00089             res->next();
00090             *pOutGearItemId = res->getInt(1);
00091         }
00092             
00093         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00094     }
00095         
00096     void DbProcedures::createPlayer(const std::string& pInLogin, const std::string& pInPassword, int* pOutId)
00097     {
00098         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00099         std::auto_ptr<sql::PreparedStatement> pstmt;
00100         pstmt.reset(connection->prepareStatement("CALL create_player(?,?,@param2)"));
00101         pstmt->setString(1,pInLogin);
00102         pstmt->setString(2,pInPassword);
00103             
00104         pstmt->execute();
00105             
00106         {
00107             std::auto_ptr< sql::ResultSet > res;
00108             std::auto_ptr< sql::Statement > stmt;
00109             stmt.reset(connection->createStatement());
00110             res.reset(stmt->executeQuery("SELECT @param2 from dual"));
00111             res->next();
00112             *pOutId = res->getInt(1);
00113         }
00114             
00115         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00116     }
00117         
00118     void DbProcedures::createPlayerCharacter(int pInRaceId, int pInPlayerId, int* pOutPcId, int* pOutCharId)
00119     {
00120         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00121         std::auto_ptr<sql::PreparedStatement> pstmt;
00122         pstmt.reset(connection->prepareStatement("CALL create_player_character(?,?,@param2,@param3)"));
00123         pstmt->setInt(1,pInRaceId);
00124         pstmt->setInt(2,pInPlayerId);
00125             
00126         pstmt->execute();
00127             
00128         {
00129             std::auto_ptr< sql::ResultSet > res;
00130             std::auto_ptr< sql::Statement > stmt;
00131             stmt.reset(connection->createStatement());
00132             res.reset(stmt->executeQuery("SELECT @param2 from dual"));
00133             res->next();
00134             *pOutPcId = res->getInt(1);
00135         }
00136             
00137         {
00138             std::auto_ptr< sql::ResultSet > res;
00139             std::auto_ptr< sql::Statement > stmt;
00140             stmt.reset(connection->createStatement());
00141             res.reset(stmt->executeQuery("SELECT @param3 from dual"));
00142             res->next();
00143             *pOutCharId = res->getInt(1);
00144         }
00145             
00146         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00147     }
00148         
00149     void DbProcedures::deleteGearItem(int pInGearItemId)
00150     {
00151         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00152         std::auto_ptr<sql::PreparedStatement> pstmt;
00153         pstmt.reset(connection->prepareStatement("CALL delete_gear_item(?)"));
00154         pstmt->setInt(1,pInGearItemId);
00155             
00156         pstmt->execute();
00157             
00158         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00159     }
00160         
00161     void DbProcedures::getChar(int pInCharId, bool* isMale, int* raceId, int* agility, int* body, int* reaction, int* strength, int* charisma, int* intuition, int* logic, int* willpower, int* edge, int* edgeBurnt, int* magic, int* resonance, int* queryId)
00162     {
00163         DbStream* stream;
00164         if(*queryId == DbStream::InitStreamId)
00165             stream = DbStream::StartStream(formatString("CALL get_char(%d)",pInCharId));
00166         else
00167             stream = DbStream::RetrieveStream(queryId);
00168         if(stream == NULL)
00169             return;
00170         *isMale = stream->getBool(1);
00171         *raceId = stream->getInt(2);
00172         *agility = stream->getInt(3);
00173         *body = stream->getInt(4);
00174         *reaction = stream->getInt(5);
00175         *strength = stream->getInt(6);
00176         *charisma = stream->getInt(7);
00177         *intuition = stream->getInt(8);
00178         *logic = stream->getInt(9);
00179         *willpower = stream->getInt(10);
00180         *edge = stream->getInt(11);
00181         *edgeBurnt = stream->getInt(12);
00182         *magic = stream->getInt(13);
00183         *resonance = stream->getInt(14);
00184         if(!DbStream::CheckHasMoreRows(stream, queryId))
00185             *queryId = DbStream::InitStreamId;
00186     }
00187         
00188     void DbProcedures::getCharActiveSkills(int pInCharId, int* activeSkillId, int* rating, int* queryId)
00189     {
00190         DbStream* stream;
00191         if(*queryId == DbStream::InitStreamId)
00192             stream = DbStream::StartStream(formatString("CALL get_char_active_skills(%d)",pInCharId));
00193         else
00194             stream = DbStream::RetrieveStream(queryId);
00195         if(stream == NULL)
00196             return;
00197         *activeSkillId = stream->getInt(1);
00198         *rating = stream->getInt(2);
00199         if(!DbStream::CheckHasMoreRows(stream, queryId))
00200             *queryId = DbStream::InitStreamId;
00201     }
00202         
00203     void DbProcedures::getCharAdeptPwrs(int pInCharId, int* adeptPowerId, int* rating, int* queryId)
00204     {
00205         DbStream* stream;
00206         if(*queryId == DbStream::InitStreamId)
00207             stream = DbStream::StartStream(formatString("CALL get_char_adept_pwrs(%d)",pInCharId));
00208         else
00209             stream = DbStream::RetrieveStream(queryId);
00210         if(stream == NULL)
00211             return;
00212         *adeptPowerId = stream->getInt(1);
00213         *rating = stream->getInt(2);
00214         if(!DbStream::CheckHasMoreRows(stream, queryId))
00215             *queryId = DbStream::InitStreamId;
00216     }
00217         
00218     void DbProcedures::getCharDmg(int pInCharId, int* stunDmgTaken, int* physicalDmgTaken, int* queryId)
00219     {
00220         DbStream* stream;
00221         if(*queryId == DbStream::InitStreamId)
00222             stream = DbStream::StartStream(formatString("CALL get_char_dmg(%d)",pInCharId));
00223         else
00224             stream = DbStream::RetrieveStream(queryId);
00225         if(stream == NULL)
00226             return;
00227         *stunDmgTaken = stream->getInt(1);
00228         *physicalDmgTaken = stream->getInt(2);
00229         if(!DbStream::CheckHasMoreRows(stream, queryId))
00230             *queryId = DbStream::InitStreamId;
00231     }
00232         
00233     void DbProcedures::getCharGear(int pInCharId, int* gearId, int* location, int* rating, int* queryId)
00234     {
00235         DbStream* stream;
00236         if(*queryId == DbStream::InitStreamId)
00237             stream = DbStream::StartStream(formatString("CALL get_char_gear(%d)",pInCharId));
00238         else
00239             stream = DbStream::RetrieveStream(queryId);
00240         if(stream == NULL)
00241             return;
00242         *gearId = stream->getInt(1);
00243         *location = stream->getInt(2);
00244         *rating = stream->getInt(3);
00245         if(!DbStream::CheckHasMoreRows(stream, queryId))
00246             *queryId = DbStream::InitStreamId;
00247     }
00248         
00249     void DbProcedures::getCharKnowSkills(int pInCharId, int* knowledgeSkillId, int* rating, int* queryId)
00250     {
00251         DbStream* stream;
00252         if(*queryId == DbStream::InitStreamId)
00253             stream = DbStream::StartStream(formatString("CALL get_char_know_skills(%d)",pInCharId));
00254         else
00255             stream = DbStream::RetrieveStream(queryId);
00256         if(stream == NULL)
00257             return;
00258         *knowledgeSkillId = stream->getInt(1);
00259         *rating = stream->getInt(2);
00260         if(!DbStream::CheckHasMoreRows(stream, queryId))
00261             *queryId = DbStream::InitStreamId;
00262     }
00263         
00264     void DbProcedures::getCharQualities(int pInCharId, int* qualityId, int* rating, int* queryId)
00265     {
00266         DbStream* stream;
00267         if(*queryId == DbStream::InitStreamId)
00268             stream = DbStream::StartStream(formatString("CALL get_char_qualities(%d)",pInCharId));
00269         else
00270             stream = DbStream::RetrieveStream(queryId);
00271         if(stream == NULL)
00272             return;
00273         *qualityId = stream->getInt(1);
00274         *rating = stream->getInt(2);
00275         if(!DbStream::CheckHasMoreRows(stream, queryId))
00276             *queryId = DbStream::InitStreamId;
00277     }
00278         
00279     void DbProcedures::getCharSpells(int pInCharId, int* spellId, int* queryId)
00280     {
00281         DbStream* stream;
00282         if(*queryId == DbStream::InitStreamId)
00283             stream = DbStream::StartStream(formatString("CALL get_char_spells(%d)",pInCharId));
00284         else
00285             stream = DbStream::RetrieveStream(queryId);
00286         if(stream == NULL)
00287             return;
00288         *spellId = stream->getInt(1);
00289         if(!DbStream::CheckHasMoreRows(stream, queryId))
00290             *queryId = DbStream::InitStreamId;
00291     }
00292         
00293     void DbProcedures::getPcZone(int pInPcId, int* currentZoneId, int* queryId)
00294     {
00295         DbStream* stream;
00296         if(*queryId == DbStream::InitStreamId)
00297             stream = DbStream::StartStream(formatString("CALL get_pc_zone(%d)",pInPcId));
00298         else
00299             stream = DbStream::RetrieveStream(queryId);
00300         if(stream == NULL)
00301             return;
00302         *currentZoneId = stream->getInt(1);
00303         if(!DbStream::CheckHasMoreRows(stream, queryId))
00304             *queryId = DbStream::InitStreamId;
00305     }
00306         
00307     void DbProcedures::getPlayerCharacters(int pInPlayerId, int* ID, int* queryId)
00308     {
00309         DbStream* stream;
00310         if(*queryId == DbStream::InitStreamId)
00311             stream = DbStream::StartStream(formatString("CALL get_player_characters(%d)",pInPlayerId));
00312         else
00313             stream = DbStream::RetrieveStream(queryId);
00314         if(stream == NULL)
00315             return;
00316         *ID = stream->getInt(1);
00317         if(!DbStream::CheckHasMoreRows(stream, queryId))
00318             *queryId = DbStream::InitStreamId;
00319     }
00320         
00321     void DbProcedures::setCharActiveSkill(int pInCharId, int pInSkillId, int pInRating)
00322     {
00323         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00324         std::auto_ptr<sql::PreparedStatement> pstmt;
00325         pstmt.reset(connection->prepareStatement("CALL set_char_active_skill(?,?,?)"));
00326         pstmt->setInt(1,pInCharId);
00327         pstmt->setInt(2,pInSkillId);
00328         pstmt->setInt(3,pInRating);
00329             
00330         pstmt->execute();
00331             
00332         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00333     }
00334         
00335     void DbProcedures::setCharAdeptPwr(int pInCharId, int pInPwrId, int pInRating)
00336     {
00337         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00338         std::auto_ptr<sql::PreparedStatement> pstmt;
00339         pstmt.reset(connection->prepareStatement("CALL set_char_adept_pwr(?,?,?)"));
00340         pstmt->setInt(1,pInCharId);
00341         pstmt->setInt(2,pInPwrId);
00342         pstmt->setInt(3,pInRating);
00343             
00344         pstmt->execute();
00345             
00346         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00347     }
00348         
00349     void DbProcedures::setCharDmg(int pInCharId, int pInStunDmg, int pInPhysDmg)
00350     {
00351         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00352         std::auto_ptr<sql::PreparedStatement> pstmt;
00353         pstmt.reset(connection->prepareStatement("CALL set_char_dmg(?,?,?)"));
00354         pstmt->setInt(1,pInCharId);
00355         pstmt->setInt(2,pInStunDmg);
00356         pstmt->setInt(3,pInPhysDmg);
00357             
00358         pstmt->execute();
00359             
00360         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00361     }
00362         
00363     void DbProcedures::setCharKnowSkill(int pInCharId, int pInSkillId, int pInRating)
00364     {
00365         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00366         std::auto_ptr<sql::PreparedStatement> pstmt;
00367         pstmt.reset(connection->prepareStatement("CALL set_char_know_skill(?,?,?)"));
00368         pstmt->setInt(1,pInCharId);
00369         pstmt->setInt(2,pInSkillId);
00370         pstmt->setInt(3,pInRating);
00371             
00372         pstmt->execute();
00373             
00374         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00375     }
00376         
00377     void DbProcedures::setCharMentAttr(int pInCharId, int pInCharisma, int pInIntuition, int pInLogic, int pInWillpower)
00378     {
00379         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00380         std::auto_ptr<sql::PreparedStatement> pstmt;
00381         pstmt.reset(connection->prepareStatement("CALL set_char_ment_attr(?,?,?,?,?)"));
00382         pstmt->setInt(1,pInCharId);
00383         pstmt->setInt(2,pInCharisma);
00384         pstmt->setInt(3,pInIntuition);
00385         pstmt->setInt(4,pInLogic);
00386         pstmt->setInt(5,pInWillpower);
00387             
00388         pstmt->execute();
00389             
00390         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00391     }
00392         
00393     void DbProcedures::setCharPhysAttr(int pInCharId, int pInAgility, int pInBody, int pInReaction, int pInStrength)
00394     {
00395         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00396         std::auto_ptr<sql::PreparedStatement> pstmt;
00397         pstmt.reset(connection->prepareStatement("CALL set_char_phys_attr(?,?,?,?,?)"));
00398         pstmt->setInt(1,pInCharId);
00399         pstmt->setInt(2,pInAgility);
00400         pstmt->setInt(3,pInBody);
00401         pstmt->setInt(4,pInReaction);
00402         pstmt->setInt(5,pInStrength);
00403             
00404         pstmt->execute();
00405             
00406         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00407     }
00408         
00409     void DbProcedures::setCharQuality(int pInCharId, int pInQualityId, int pInRating)
00410     {
00411         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00412         std::auto_ptr<sql::PreparedStatement> pstmt;
00413         pstmt.reset(connection->prepareStatement("CALL set_char_quality(?,?,?)"));
00414         pstmt->setInt(1,pInCharId);
00415         pstmt->setInt(2,pInQualityId);
00416         pstmt->setInt(3,pInRating);
00417             
00418         pstmt->execute();
00419             
00420         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00421     }
00422         
00423     void DbProcedures::setCharSpecAttr(int pInCharId, int pInEdge, int pInEdgeBurnt, int pInMagic, int pInResonance)
00424     {
00425         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00426         std::auto_ptr<sql::PreparedStatement> pstmt;
00427         pstmt.reset(connection->prepareStatement("CALL set_char_spec_attr(?,?,?,?,?)"));
00428         pstmt->setInt(1,pInCharId);
00429         pstmt->setInt(2,pInEdge);
00430         pstmt->setInt(3,pInEdgeBurnt);
00431         pstmt->setInt(4,pInMagic);
00432         pstmt->setInt(5,pInResonance);
00433             
00434         pstmt->execute();
00435             
00436         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00437     }
00438         
00439     void DbProcedures::setCharSpell(int pInCharId, int pInSpellId)
00440     {
00441         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00442         std::auto_ptr<sql::PreparedStatement> pstmt;
00443         pstmt.reset(connection->prepareStatement("CALL set_char_spell(?,?)"));
00444         pstmt->setInt(1,pInCharId);
00445         pstmt->setInt(2,pInSpellId);
00446             
00447         pstmt->execute();
00448             
00449         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00450     }
00451         
00452     void DbProcedures::setGearItemOwner(int pInGearId, int pInOwnerCharId)
00453     {
00454         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00455         std::auto_ptr<sql::PreparedStatement> pstmt;
00456         pstmt.reset(connection->prepareStatement("CALL set_gear_item_owner(?,?)"));
00457         pstmt->setInt(1,pInGearId);
00458         pstmt->setInt(2,pInOwnerCharId);
00459             
00460         pstmt->execute();
00461             
00462         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00463     }
00464         
00465     void DbProcedures::setPcZone(int pInPcId, int pInZoneId)
00466     {
00467         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00468         std::auto_ptr<sql::PreparedStatement> pstmt;
00469         pstmt.reset(connection->prepareStatement("CALL set_pc_zone(?,?)"));
00470         pstmt->setInt(1,pInPcId);
00471         pstmt->setInt(2,pInZoneId);
00472             
00473         pstmt->execute();
00474             
00475         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00476     }
00477         
00478     void DbProcedures::setPlayerNickname(int pInPlayerId, const std::string& pInNickname)
00479     {
00480         sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
00481         std::auto_ptr<sql::PreparedStatement> pstmt;
00482         pstmt.reset(connection->prepareStatement("CALL set_player_nickname(?,?)"));
00483         pstmt->setInt(1,pInPlayerId);
00484         pstmt->setString(2,pInNickname);
00485             
00486         pstmt->execute();
00487             
00488         SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);
00489     }
00490 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net