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 
 
Table Creation

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Darelius



Joined: 08 Dec 2008
Posts: 8

PostPosted: Mon Dec 08, 2008 2:21    Post subject: Table Creation Reply with quote

I missed a valid function for the table creation, so i wrote one and post it here, if you want.
(yes i have not tested it yet, but will do soon)

Code:

// Creates a table with the Table for tzhe game
// sTable : Name of the Table to create
// iDataBaseType : Type of the Database
//  0 = SQLite
//  1 = MySQL (Standard)
//  2 = Access
void SQLCreateTable (string sTable="pwdata", int iDataBaseType=1);
void SQLCreateTable (string sTable="pwdata", int iDataBaseType=1)
{
string sSQLite=" ("+
        "player varchar(64) NOT NULL default '~',"+
        "tag varchar(64) NOT NULL default '~'," +
        "name varchar(64) NOT NULL default '~'," +
        "val text," +
        "expire int(11) default NULL," +
        "last timestamp NOT NULL default current_timestamp," +
        "PRIMARY KEY (player,tag,name)" +
        ")";
string sMySQL=" (" +
        "player varchar(64) NOT NULL default '~'," +
        "tag varchar(64) NOT NULL default '~'," +
        "name varchar(64) NOT NULL default '~'," +
        "val text," +
        "expire int(11) default NULL," +
        "last timestamp NOT NULL default CURRENT_TIMESTAMP," +
        "PRIMARY KEY  (player,tag,name)" +
        ") ENGINE=MyISAM DEFAULT CHARSET=latin1;";

string sAccess=" (" +
        "player text(64)," +
        "tag text(64)," +
        "name text(64)," +
        "val memo," +
        "expire text(4)," +
        "last date)";
string sDataBaseDirect=sMySQL;
if (iDataBaseType==0){sDataBaseDirect=sSQLite;}
else if (iDataBaseType==2){sDataBaseDirect=sAccess;}
else {sDataBaseDirect=sMySQL;}
SQLExecDirect("CREATE TABLE "+sTable+sDataBaseDirect);
}


So the command
SQLCreateTable ("table",0);
should create a table namend "table" and the number after it stands for database SQLite...
Every user could edit the standard for personal purposes...

But for more "tables" this function will be great in basis, i thought...


Any comments?


...DX
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Mon Dec 08, 2008 18:44    Post subject: Reply with quote

Yes, I have a question... why is this in Windows Development? Shouldn't it be in Database Related or Scripts and Modules?

The function itself looks alright, though most people will set up all their tables externally before starting. And the bog standard pwdata table is not the only format for storing persistent data - most PW owners will probably end up using lots of different tables each with a different function and different fields, all properly normalized, linked and optimized.

Still, what you have there is great for those who want a little bit more oomph out of their bog standard NWNX installation by adding the ability to split their data into tables related to their use, thus speeding up access times a bit and allowing for selective data wipes.
Back to top
View user's profile Send private message
Darelius



Joined: 08 Dec 2008
Posts: 8

PostPosted: Mon Dec 08, 2008 19:11    Post subject: Reply with quote

Fireboar wrote:
Yes, I have a question... why is this in Windows Development? Shouldn't it be in Database Related or Scripts and Modules?


I have no idea of the work in this forum and posted on first category i thought it could be good there, sorry.


Fireboar wrote:

The function itself looks alright, though most people will set up all their tables externally before starting. And the bog standard pwdata table is not the only format for storing persistent data - most PW owners will probably end up using lots of different tables each with a different function and different fields, all properly normalized, linked and optimized.


I tested it and it works fine


Fireboar wrote:

Still, what you have there is great for those who want a little bit more oomph out of their bog standard NWNX installation by adding the ability to split their data into tables related to their use, thus speeding up access times a bit and allowing for selective data wipes.


Thatz was the intention.
In addition, i could add a function for personal creating of tables with more entrys so far.

I thought to make some "own" sql data requests and not using the aps_include (i renamed it to fix it to my script-name-standard), but i decided to keep it, because i have enough work to do with my module (should be in internet but working alone is depressive), so i still use the standard and make some more entrys instead of longer entrys.


...DX
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development 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