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 
 
question of a newbbie

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



Joined: 28 Jul 2008
Posts: 1

PostPosted: Mon Jul 28, 2008 3:08    Post subject: question of a newbbie Reply with quote

hi guys

i'm using you tool, but i can't open the start module, when i try to do this toolset goes in crash,.

but this is not important Razz

the question is how can i use the function for get a row from a query?

for example i want to transfer on a variable the result of query:

select id from table_name where table.id=2

and i want to transfer in the script on variable PGID the result (2)

for now i use for to do insert and update the SQLExec("query")

thanks for the help Very Happy

Mauro
Back to top
View user's profile Send private message
Saulus



Joined: 24 Mar 2008
Posts: 7

PostPosted: Mon Jul 28, 2008 19:37    Post subject: Reply with quote

Well lets say you had

int nPCvar = GetLocalInt(oPC, "SOME_VALUE");
string sPCvar = IntToString(nPCvar);

sSQL = "select id from table_name where table.id="+sPCvar;

SQLExecDirect(sSQL);

Is that what you were asking?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Asparius



Joined: 18 Sep 2007
Posts: 52

PostPosted: Tue Jul 29, 2008 17:13    Post subject: Reply with quote

Ok. First - getting a row from the query:

Code:

#include "aps_include"
void main()
{
 string sReply;

 SQLExecDirect ("[i]put your query here[/i]");

 while (SQLFetch() == SQL_SUCCESS)
    {
     //first column of the reply from SQL
     sReply = SQLGetData(1);
     //Now you can do something with reply

     //...then check second column
     sReply = SQLGetData(2);
     //again do something...
     ///etc
    }

}


If you expect only one reply, replace while with if. If you are sure there WILL be a reply, leave only SQLFetch() (i'd advise against that though - better to be prepared for any errors, for instance losing db connection etc.).


As I understood you want to do something like this:

Code:

#include "aps_include"
void main()
{
 string sReply;
 int nPGID;

 SQLExecDirect ("SELECT id FROM table_name WHERE table.id=2");

 if (SQLFetch() == SQL_SUCCESS)
    {
     sReply = SQLGetData(1);
     nPGID = StringToInt (sReply);
    }
 else
    {
     //something is wrong - no reply from database.
     //insert here code to be executed in this case.
    }
}
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Jul 30, 2008 0:07    Post subject: Reply with quote

and make sure you SQL syntax is correct
select id from table where table.id=2 or
select id from table_name where table_name.id=2 or
select id from table_name t where t.id=2
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