View previous topic :: View next topic |
Author |
Message |
nevarim
Joined: 28 Jul 2008 Posts: 1
|
Posted: Mon Jul 28, 2008 3:08 Post subject: question of a newbbie |
|
|
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
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
Mauro |
|
Back to top |
|
|
Saulus
Joined: 24 Mar 2008 Posts: 7
|
Posted: Mon Jul 28, 2008 19:37 Post subject: |
|
|
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 |
|
|
Asparius
Joined: 18 Sep 2007 Posts: 52
|
Posted: Tue Jul 29, 2008 17:13 Post subject: |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Wed Jul 30, 2008 0:07 Post subject: |
|
|
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 |
|
|
|