logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Method of Automatic Table Creation?

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
Spawnblade



Joined: 28 Mar 2009
Posts: 3

PostPosted: Sat Mar 28, 2009 21:01    Post subject: Method of Automatic Table Creation? Reply with quote

As the subject indicates. Just taught myself the basics of nwnx2 and sqlite a few days back in order to move away from using Bioware's generally slower database.

Now perhaps I'm spoiled, but NWN's default database was easily organized via creating new campaign databases that could be simply wiped if desired. I had thought on first look that the table column would accommodate this nicely using ODBC2.. However I quickly learned that sqlite will not automatically create tables that are being referenced.

So is there any code I could possibly add to the ODBC2 functions to allow this dynamic table creation when a table of that name doesn't exist?

If not, is the best method to simply rewrite every function to accommodate an extra 'identifier' variable for organizational purposes?

And last, what program do you guys recommend for viewing/editing the actual database (any third party programs that work graphically rather than constantly utilizing command lines?) And will any of them sort based on column information to allow better viewing? (I've determined SQLiteCC to be inadequate for me Sad)

I appreciate any help that can be given Smile. I'll go back to searching the topics to ensure I didn't miss any relevant info.
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Sat Mar 28, 2009 21:40    Post subject: Reply with quote

You could do that, yes, but you would probably be better served by figuring out what data you're storing, what tables you want to store it in, and how they'll relate to each other, if at all, intead of just trying to automate table creation. When I first transferred over, I simply copied all my bioware vars into the default table that comes with nwnx, merging the campaign name with the variable name. There are a number of ways to go about that, though, and the best is really dependant on the particular data you're storing. I've posted examples of conversion from bioware to mysql, but I don't remember whether it was here or on the bioboards scripting forum, so you may want to search both boards.

Funky
Back to top
View user's profile Send private message
Spawnblade



Joined: 28 Mar 2009
Posts: 3

PostPosted: Sat Mar 28, 2009 22:15    Post subject: Reply with quote

FunkySwerve wrote:
You could do that, yes, but you would probably be better served by figuring out what data you're storing, what tables you want to store it in, and how they'll relate to each other, if at all, intead of just trying to automate table creation. When I first transferred over, I simply copied all my bioware vars into the default table that comes with nwnx, merging the campaign name with the variable name. There are a number of ways to go about that, though, and the best is really dependant on the particular data you're storing. I've posted examples of conversion from bioware to mysql, but I don't remember whether it was here or on the bioboards scripting forum, so you may want to search both boards.

Funky


Thanks for the heads. Just realized that that's the true power of switching over to SQL from the Bioware database.. I was so used to that clunky thing that I wasn't thinking about actually designing tables to my liking with which to retrieve information.

And I just figured out how the scripting is working so I can design my own functions. Which seems necessary to actually design a clean database.

Thank you for the response though, I'll check out those examples just to make sure I'm doing it right, though I have a sinking suspicion this is rather easy now, if a bit time consuming to actually set up all the functions.
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Sun Mar 29, 2009 0:31    Post subject: Reply with quote

You don't actually - SQLExecDirect is a competent NWNX database scripter's best friend. Just use that to call SELECT, INSERT or UPDATE queries to manage rows and columns of data however you like.

To be honest, using the SetPersistent functions exclusively is a bit like seeing an ENORMOUS and delicious feast right in front of you, for you, with just about everything you could possibly want to eat, then just having a sandwich. Sure, it's nice, but you could do so much more.
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Sun Mar 29, 2009 8:14    Post subject: Reply with quote

Fireboar wrote:
You don't actually - SQLExecDirect is a competent NWNX database scripter's best friend.

I imagine he was referring to the Set/GetPersistent functions, which ARE a bit limiting. We still use SQLExecDirect, but all our queries have been custom ones for a long time. The basics, like ExecDirect and SQLGetData are still the core of our setup, though acaos did write a replacement for ExecDirect that eliminates the messy string math, allowing you to write queries as you would normally:

Code:

void SQLExecStatement(string sSQL, string sStr0="",
            string sStr1="", string sStr2="", string sStr3="", string sStr4="",
            string sStr5="", string sStr6="", string sStr7="", string sStr8="",
            string sStr9="", string sStr10="", string sStr11="", string sStr12="",
            string sStr13="", string sStr14="", string sStr15="")
{
    int nPos, nCount = 0;

    string sLeft = "", sRight = sSQL;

    while ((nPos = FindSubString(sRight, "?")) >= 0) {
        string sInsert;

        switch (nCount++) {
            case 0:  sInsert = sStr0; break;
            case 1:  sInsert = sStr1; break;
            case 2:  sInsert = sStr2; break;
            case 3:  sInsert = sStr3; break;
            case 4:  sInsert = sStr4; break;
            case 5:  sInsert = sStr5; break;
            case 6:  sInsert = sStr6; break;
            case 7:  sInsert = sStr7; break;
            case 8:  sInsert = sStr8; break;
            case 9:  sInsert = sStr9; break;
            case 10: sInsert = sStr10; break;
            case 11: sInsert = sStr11; break;
            case 12: sInsert = sStr12; break;
            case 13: sInsert = sStr13; break;
            case 14: sInsert = sStr14; break;
            case 15: sInsert = sStr15; break;
            default: sInsert = "*INVALID*"; break;
        }

        sLeft += GetStringLeft(sRight, nPos) + "'" + SQLEncodeSpecialChars(sInsert) + "'";
        sRight = GetStringRight(sRight, GetStringLength(sRight) - (nPos + 1));
    }

    SetLocalString(GetModule(), "NWNX!ODBC!EXEC", sLeft + sRight);
}


Here's an example usage:

Code:

SQLExecStatement("SELECT * FROM wallet_history WHERE wh_cdkey = ? AND (wh_tstamp LIKE ? OR wh_log LIKE ?) ORDER BY wh_id DESC LIMIT 20", sCDKey, sSearch, sSearch);


Gets rid of all the pesky "+" and avoids some irritating and hard-to-spot typos.

Funky
Back to top
View user's profile Send private message
Spawnblade



Joined: 28 Mar 2009
Posts: 3

PostPosted: Mon Mar 30, 2009 2:03    Post subject: Reply with quote

Thought I'd take a peek at this thread again.

Thanks for the replies, again. Spent the last 16ish hours writing up a couple thousand lines of custom functions for our database Razz. It was pretty easy once I realized I had a pretty high level of control over the system. I really pity anyone who actually uses the bioware equivalents (the default get/setpersistents, etc..)

I am curious though, why do the strings use the SQLGetData function, but the ints and floats work through the module variables?

I wish SQL had as smooth a method of retrieving data through NWNX as it does when inputting it Sad.

Wow talk about a learning experience though.
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Mon Mar 30, 2009 10:06    Post subject: Reply with quote

About the float/int return stuff. I think teh answer is pretty simple: an NWN function can only return one variable type, and string can represent both floats and ints, but int and float can't represent strings.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group