Jump to content

Character Database Access from mangosscript.dll


Recommended Posts

Posted

Hi,

I have a teleporter npc... it requires SQL queries and right now im using this format to open a new connection to the character db:

    DatabaseType SDloginDatabase;
   std::string strLoginDBinfo = SD2Config.GetStringDefault("LoginDatabaseInfo", "");
   if (strLoginDBinfo.empty())
   {
       error_log("SD2: Missing Login database info from configuration file. Load database aborted.");
       return;
   }
   if (!SDloginDatabase.Initialize(strLoginDBinfo.c_str()))
   {
       error_log("SD2: Unable to connect to login Database. Load database aborted.");
       return;
   }
   SDloginDatabase.HaltDelayThread();

by adding an extra config ... but this method starts a connection every time the teleporter npc is used to teleport, and adds makes my MySQL server 5x heavier...

CAn some one please tell me how to open a connection on a variable which will not be deleted on the end of script execution...?

Like when mangos loads... it'll also load character db in mangosscript.dll and will be able to accessed by that variable any time i want... without starting a new connection every time..

Thanks :)

Posted

Dude .. they only use it for start up... then the connection closes i think... i tried alot ... spent about 6 hours on it ... at the end.. i had to use the dangerous way

Posted
#include "Database/DatabaseEnv.h"

Then use CharacterDatabase global variable.

Yay! Link errors!

Dude .. they only use it for start up... then the connection closes i think... i tried alot ... spent about 6 hours on it ... at the end.. i had to use the dangerous way

No it doesn't. I don't know what the dangerous way is, but if you do it like the other DB connection in SD2 it will work.

Posted

SD2 uses SQL querys to the DB at startup, but didn't think the connection is closed after that maybe you can use that connection or just open a connection to the other DB at startup and don't close the connection?

hope it helped

  • 11 months later...
Posted

This thread is quite old but i write for future lookups

You can use a cheat something like this:

SD2Database.query("INSERT INTO characters.table ....

where characters is the name of your char db

Posted
This thread is quite old but i write for future lookups

You can use a cheat something like this:

SD2Database.query("INSERT INTO characters.table ....

where characters is the name of your char db

No you can't.

Posted

No you can't.

Why do you say that?

I have recommend this way because I use it and works perfectly.

But I do a correction:

SD2Database.PExecute("INSERT INTO characters.

Posted

It's a bad idea for a very simple reason, SD2 database is configured independently from the other DBs, so assuming you have access to other DBs from SD2 DB connection is just false.

And the name of the character DB depends on the configuration too, so this simply cannot work in any generic way.

So better listen to what zergtmn says ;)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use