Forum > Serverside Modding

[C++] Database query

(1/2) > >>

XxXGenesisXxX:
I'm trying to get this gossip script to get the players characters GUID and a creatures Entry (not GUID) then INSERT them into a table. But I can't seem to have these in the same line:

--- Code: ---plr->GetGUID(), pCreature->GetEntry()
--- End code ---


Which came from this:


--- Code: ---CharacterDatabase.Execute("INSERT INTO player_shop (ownerguid, vendor) VALUES(%u, %u)", plr->GetGUID(), pCreature->GetEntry());
--- End code ---

However all that did is insert the GUID into the ownerguid column, and then set a 0 for the vendor ID. So then I tried this:


--- Code: ---CharacterDatabase.Execute("INSERT INTO player_shop (ownerguid, vendor) VALUES(%u, %u)", plr->GetGUID(), pCreature->GetGUID());
--- End code ---

And it worked as it should. But I don't want the GUID I want the "entry" from the creature table. So then I tried this:


--- Code: ---CharacterDatabase.Execute("INSERT INTO player_shop (ownerguid, vendor) VALUES(%u, %u)", plr->GetGUID(), pCreature->GetEntry());
CharacterDatabase.Execute("INSERT INTO player_shop (vendor) VALUES(%u)", pCreature->GetEntry());
--- End code ---

Which sort of worked, it got both the player character GUID and the creatures entry ID absolutely fine, but as expected it puts it into 2 individual rows.

Also, while the creature_proto and creature_names table use "entry" and I am using "Entry" if I use "entry" in the C++ script it comes says the class hasn't got it as a member. However I fail to see it as important since when on seperate lines it still successfully pulls the "entry" and inserts it into the table.

So can someone please correct this for me and explain why it's screwing up? Is it simply that I can't have the "Get" command twice in one query?

Steff:
Just look if the class pCreature is made form

have a method called GetEntry()

XxXGenesisXxX:
As I said this works:


--- Code: ---CharacterDatabase.Execute("INSERT INTO player_shop (vendor) VALUES(%u)", pCreature->GetEntry());
--- End code ---

It's only when they are both in the same .Execture they don't seem to.

Steff:
Perhaps try to use stringstream to build the query and give it to the CharacterDatabase.Execute Method
I personaly only use them. Don´t like the old string stuff;)


--- Code: ---#include <sstream>
#include <string>

.....

stringstream myQuery;

myQuery << "INSERT INTO player_shop (ownerguid, vendor) VALUES(" << plr->GetGUID() << "," << pCreature->GetGUID() << ")";

CharacterDatabase.Execute( myQuery.toString() );

--- End code ---

Perhaps you have to do some

plr->GetGUID().toString() and pCreature->GetGUID().toString() inside the stringstream build if you get type errors there.

XxXGenesisXxX:
Thanks for the reply again Steff. Tried as you said with the stringsstream method, and I do indeed need to add a class for toString to the sstream. I don't suppose you could please elaborate on that, I haven't done much work editing standard library files before.

Navigation

[0] Message Index

[#] Next page

Go to full version