Author Topic: Need help storing a DB object  (Read 346 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Need help storing a DB object
« on: July 17, 2011, 09:27:34 pm »


               Greetings,

Sorry if this is the wrong place to post this(I got no answer yet on NWNX forums).

I'm currently debugging a custom DB item storage system, storing and retrieving items from a NPC wich in turn is stored in a MySQL table. The table's field used to store the NPC is BLOB type. The Get and Set functions posted below do not work, however. I mean, no storage or retrieval is currently possible. Anyone has an idea as to where the syntax error(s) might be?

void SetPersistentObject(object oPC, object oObject)
{
   string sKey = GetPCPublicCDKey(oPC, TRUE);
   string sSQL = "INSERT INTO bank(cdkey,xp,gold,storer) VALUES('" + sKey + "','0','0',%s) ON DUPLICATE KEY UPDATE storer=%s";
   SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
   StoreCampaignObject("NWNX", "-", oObject);
}

object GetPersistentObject(object oPC, object oOwner)
{
   string sKey = GetPCPublicCDKey(oPC, TRUE);
   string sSQL = "SELECT storer FROM bank WHERE cdkey='" + sKey + "'";
   SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
   if(!GetIsObjectValid(oOwner)) oOwner = oPC;
   return RetrieveCampaignObject("NWNX", "-", GetLocation(oOwner), oOwner);
}

My odbc log:

o Got request (scorco): SELECT storer FROM bank WHERE cdkey='Q7KUVYJJ'
o Got request (scorco): INSERT INTO bank(cdkey,xp,gold,storer) VALUES('Q7KUVYJJ','0','0',~s) ON DUPLICATE KEY UPDATE storer=~s
! SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
o Got request (scorco): SELECT storer FROM bank WHERE cdkey='Q7KUVYJJ'
o Got request (scorco): INSERT INTO bank(cdkey,xp,gold,storer) VALUES('Q7KUVYJJ','0','0',~s) ON DUPLICATE KEY UPDATE storer=~s
! SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Thank you very much in advance

Kato

 
               
               

               


                     Modifié par Kato_Yang, 17 juillet 2011 - 08:38 .
                     
                  


            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Need help storing a DB object
« Reply #1 on: July 17, 2011, 09:39:05 pm »


               Try removing ON DUPLICATE KEY UPDATE part.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Need help storing a DB object
« Reply #2 on: July 17, 2011, 09:52:52 pm »


               Right on, Virusman, thanks a lot!! I guess I'll simply have to delete the old NPC before storing the new one as a way around ON DUPLICATE KEY UPDATE... '<img'>
               
               

               


                     Modifié par Kato_Yang, 17 juillet 2011 - 08:53 .