Aller au contenu

Photo

Need help storing a DB object


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
Kato -

Kato -
  • Members
  • 392 messages
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 .


#2
virusman

virusman
  • Members
  • 282 messages
Try removing ON DUPLICATE KEY UPDATE part.

#3
Kato -

Kato -
  • Members
  • 392 messages
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... :)

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