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 
 
Verrrry basic databse questions

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



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Jul 28, 2010 3:31    Post subject: Verrrry basic databse questions Reply with quote

So I made the decision to migrate from NBDE to SQLite in the hopes of increased efficiency and potentially more dynamic uses of my data.

However, I am not a database guy and have only the NWN database as a reference point that learned from. As a result, I'm a bit disoriented - I know even SQLite is more dynamic than NBDE, but am having a hard time conceptualizing the benefits. I think NBDE warped my thinking about how to approach databases and need help breaking out of the mental box that it put me in.

I have installed NWNX2 and the demo mod and successfully created/stored/retrieved the string and the object.

With my mod using NBDE, I have 26 campaign "tables" that different data are stored to. A sample of the tables include:
faction data
Player region
dmfi
persistent clock
guild
journals
message board
quest boss settings
...and the list goes on.

My questions may be very basic, but would be extremely helpful to hear from some experts who have some experience with these basic types of data storage/retrieval efforts and also more advanced usage.

My specific questions:
1) Should I seek to replicate each individual table in SQLite to replace the NBDE writes (vs. the standard pwdata table that the aps_demo mod creates)?
2) NBDE needed "flushing" to write the data to the db. Does SQLite require the same thing occasionally?
3) How could the idea of a relational database provide benefits over NBDE given the above tables (i.e. what do I need to consider to evaluate the need to link tables or given the example tables above, what kind of benefits could linking the tables provide? What are some other possible benefits?)
4) If I were to create a new table, do i need to name the fields as the name they'll be called in the script or can I set it to a generic name?
For example, in my database wrapper script, a call to SetDBInt rearranges the data to write to the aps_include function of SetPersistentInt

void SetDBInt(string sCampaign, string sVariable, int nValue, object oPC)
{
//NBDE_SetCampaignInt(sCampaign,sVariable,nValue,oPC);
SetPersistentInt (oPC, sVariable, nValue, 0, sCampaign);
}

Then, if a particular table would have the following:
SetDBInt ("Message Board", "NumPosts", 10, oPC), does my SQLite table need to have a field called "NumPosts" or would a field name "sVariable" be sufficient?

Thank you for your help. Your insight is much appreciated.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Wed Jul 28, 2010 22:56    Post subject: Re: Verrrry basic databse questions Reply with quote

I've never used NBDE (nor the campaign DB in general), but I'll give my two cents.

BelowTheBelt wrote:
1) Should I seek to replicate each individual table in SQLite to replace the NBDE writes (vs. the standard pwdata table that the aps_demo mod creates)?

Your choice. I probably would use different tables for most of those systems, but do whatever feels more maintainable for you.

BelowTheBelt wrote:
2) NBDE needed "flushing" to write the data to the db. Does SQLite require the same thing occasionally?

Nope.

BelowTheBelt wrote:
3) How could the idea of a relational database provide benefits over NBDE given the above tables (i.e. what do I need to consider to evaluate the need to link tables or given the example tables above, what kind of benefits could linking the tables provide? What are some other possible benefits?)

You could see performance benefits from setting appropriate primary keys, indexes, etc. Frankly, though, I wouldn't worry too much about having a "proper" relational DB for NWN purposes.

BelowTheBelt wrote:
4) If I were to create a new table, do i need to name the fields as the name they'll be called in the script or can I set it to a generic name?

The Get/SetPersistent* functions assume the player,tag,name,val,expire,last structure of the pwdata table. When you call SetPersistentInt(oPC, sVariable, nValue, 0, sCampaign), oPC determines player and tag, sVariable determines name, nValue determines val, iExpiration (or in this case 0) determines expire, and sCampaign determines the database table to use. (last is updated automagically.)

SetDBInt ("Message Board", "NumPosts", 10, oPC) will, therefore, insert or update a row in the table "Message Board" with name "NumPosts", value 10, and player/tag corresponding to the PC.

Hope that clears things up a bit!
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Jul 28, 2010 23:28    Post subject: Reply with quote

Thanks, that clears it up a lot.

Regarding the example of SetPersistentInt....

It appears that each of the aps_demo functions involve writing to an object (oPC in the example). What if I just want to write some data to a table for retrieval later?

For example, I"ve set up the following table and fields:

SendMessageToPC(GetLastUsedBy(), "Creating Table 'AR_BOSS_DB' for SQLite...");
SQLExecDirect("CREATE TABLE AR_BOSS_DB (" +
"dungeon varchar(3) NOT NULL default '000'," +
"quest_setting INTEGER (2) NOT NULL default '00'," +
"expire int(11) default NULL," +
"last timestamp NOT NULL default current_timestamp," +
"PRIMARY KEY (dungeon)" +
")");

so...in order to write to this database, I can't use the SetPersistentInt because there's no object as required by the function, correct? Does that mean that rather than using a function I have to use some SQL command like INSERT to write to the db?

Thanks.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Thu Jul 29, 2010 0:28    Post subject: Reply with quote

BelowTheBelt wrote:
It appears that each of the aps_demo functions involve writing to an object (oPC in the example). What if I just want to write some data to a table for retrieval later?

You could just use the module itself as the object for one-off, module-wide data.
BelowTheBelt wrote:
so...in order to write to this database, I can't use the SetPersistentInt because there's no object as required by the function, correct? Does that mean that rather than using a function I have to use some SQL command like INSERT to write to the db?

You can't use SetPersistentInt (or any of its siblings) when the table doesn't use the same structure as pwdata. Under those circumstances, yes, you get to write some SQL!
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 1:23    Post subject: Reply with quote

So SetPersistentInt writes to both the object (oPC or oModule or another object) AND to a table in the database? Any sense of why that was done (maybe to have the data preloaded in mod when it's set)? Seems a bit redundant to write it to both spots.

Just trying to wrap my head around when would be appropriate to use the SQLite db or when the campaign db or writing to an object in the game would be about the same.

I'm thinking the best candidates are sets of large records that get accessed frequently (spawn lists, persistent item storage, merchant stores, complicated crafting systems, player factions... )

Are there benefits to doing smaller tables that won't be accessed much? In the previous example, there will probably be less than 100 records that will only infrequently be accessed (client login, each quest completion, occasional dm tool use...).

Thanks for answering my questions.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Thu Jul 29, 2010 1:59    Post subject: Reply with quote

BelowTheBelt wrote:
So SetPersistentInt writes to both the object (oPC or oModule or another object) AND to a table in the database?

No, just to the database. However, it uses the player (if applicable) and tag of the object to emulate storing the variable "on" an object.

BelowTheBelt wrote:
Just trying to wrap my head around when would be appropriate to use the SQLite db or when the campaign db or writing to an object in the game would be about the same.

If you're using Set/GetPersistent*, you can simply think of it as a variable stored on the object that also persists across restarts (with the caveat that two objects with the same player/tag will be ambiguous). If you don't need persistence, make it a local var, otherwise, persistent.

BelowTheBelt wrote:
I'm thinking the best candidates are sets of large records that get accessed frequently (spawn lists, persistent item storage, merchant stores, complicated crafting systems, player factions... )

Again, depends on whether you want persistence (and the convenience of being able to edit the data with an SQL tool). Spawn lists should probably be local, unless you want to be able to edit them live in the DB. The rest of that list includes some of the canonical uses of NWNX/SQL.

BelowTheBelt wrote:
Are there benefits to doing smaller tables that won't be accessed much? In the previous example, there will probably be less than 100 records that will only infrequently be accessed (client login, each quest completion, occasional dm tool use...).

I'd tend to put logging activity in its own table(s) with a custom structure, as it doesn't really fit the "variable-on-an-object" concept. Besides that, I'm not really sure what you're asking. If it's a performance question, don't worry too much about that. Focus more on organizing your data in a way that makes sense to you.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
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