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 
 
[suggestion] SQLExectDirectAndSingleFetch

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Thu Dec 14, 2006 9:22    Post subject: [suggestion] SQLExectDirectAndSingleFetch Reply with quote

Hi, the purpose of this post is to suggest a new function in nwnx_sql :

Quote:
string SQLExecDirectAndSingleFetch(string sSQL, int iCol)
{
string sReturn;
SQLExecDirect(sSQL);
if (SQLFetch()==SQL_SUCCESS)
{
sReturn = SQLGetData(iCol);
}
return sReturn;
}


Can we added this function or something like that in nwnx_sql ? That could simplify scripting... So you haven't to write those line each time you need a result...What do you think about that ?
Back to top
View user's profile Send private message
kungfoowiz



Joined: 12 Oct 2006
Posts: 61

PostPosted: Thu Dec 14, 2006 13:58    Post subject: Reply with quote

Hello, so you only want the first row's column data; or all the rows' column data put into a single string?

---
kung
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Thu Dec 14, 2006 18:52    Post subject: Reply with quote

In fact, perhap's i had misunderstanding the SQLFetch function...

If I want just one data - for example :i want to get a data named "honor" in the honor table witch corresponding to a player name and his Id. There is just one row corresponding to Player name...

I had to make my script like that, no ? :
[quote]

void main()
{

object oPlayer = GetPCSPeaker();
string sName = GetName(oPlayer);
string sReturn;
string sSQL;
sSQL = "SELECT honor FROM honor WHERE Player="+sName;
SQLExectDirect(sSQL)

if (SQLFetch() == SQL_SUCCESS)
{
sReturn=SQLGetData(1);
}

SendMessageToPC(oPlayer, "you have "+sReturn+" point of honor");
}

But if i have the same request for another table and column...I need to rewriter the same type of script...What i suggest is to make a generic script in nwnx_sql with alllow to have just one function to cast...So it can simplify the scripting...

But if it's possible to make on function gneric for more than one row...Why not Very Happy

Perhaps i said something stupid, i'm not a professional developper !
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Fri Dec 15, 2006 21:58    Post subject: Reply with quote

So you suggest a nwscript function that does something like this:

1) SQLExecAndFetch("SELECT honor FROM honor WHERE Player='XYZ'");
2) The functions executes the statement, and
3) returns the first column of the first row as a string ?

Is that what you want ?
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Kallistor



Joined: 09 Dec 2006
Posts: 13

PostPosted: Fri Dec 15, 2006 22:56    Post subject: Reply with quote

I think what you are asking is for a generic script to access all tables that you create. Currently I have four seperate tables - players, characters, quests and module. I use generic functions SQLSetString, SQLGetString, SQLSetInteger and SQLGetInteger to access all four tables. What I do is in the function call a GetWhereStatement and pass the table to that WhereStatement to generate the WHERE part, same for INSERT also. I do this as all four tables have different keys, and I believe that is what you were eluding too with your second post????? Oh yeah I also use a function to generate the key of the table. Anyway here is my SELECT statement where sKey and sWhere are generated from the above mentioned functions

Code:
    string sSQL = "SELECT " + sKey + " FROM " + sTable + " WHERE " + sWhere;


You can use the sWhere string later for the UPDATE string also if you are Setting data in the DB.

If this is what you are actually enquiring about then I can provide the functions to generate these generic table calls.
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Fri Dec 15, 2006 22:57    Post subject: mmm yes something like that Reply with quote

Quote:

So you suggest a nwscript function that does something like this:

1) SQLExecAndFetch("SELECT honor FROM honor WHERE Player='XYZ'");
2) The functions executes the statement, and
3) returns the first column of the first row as a string ?

Is that what you want ?


It's more :
Quote:

So you suggest a nwscript function that does something like this:

1) SQLExecAndFetch(strin sSQL, int nCol);
2) The functions executes the statement, and
3) returns the ncolumn of the first row as a string ?



But yes it was what isuggest...

Have i said something Stupid ? Crying or Very sad
It's just a idea to simplify the code in our script...

rather than make a lot of script with SQLExectDirect and Next an SQLFetch, why not add a function in nwnx_sql that do something like that...?

It's not easy to write what you have in mind in english when it's not your native langage... Embarassed

Perhaps we could do a generic function that could launch a request (SQLExectDirect) and return the number of value that we ask it to do (while (SQLFetch()==SQL_SUCCESS........)...

Or perhap i had misunderstanding how to use nwnx4...
How do you recover a value that is stocked in a database ?
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sat Dec 16, 2006 21:41    Post subject: Reply with quote

The idea isn't stupid at all. In fact, I think this might be a nice little function that should be added to the nwscript include file.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Sat Dec 16, 2006 23:13    Post subject: Reply with quote

By default, nCol could equal 1.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Sun Dec 17, 2006 10:56    Post subject: Reply with quote

Quote:

If this is what you are actually enquiring about then I can provide the functions to generate these generic table calls.


Yes that sound like what i want ! Very Happy Very Happy thanks !

Could you post your scripts ?
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Tue Dec 19, 2006 13:21    Post subject: Reply with quote

Well, in the same style...

Is it possible to let INSERT return the ID of the table entry upon SQLExecAndFetch? 0 would still mean a failure, of course. It would make the access of certain records via a variable stored on a PC or item a breeze.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> 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