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 
 
SQLQuery in a SQL Query while loop

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



Joined: 27 Sep 2005
Posts: 2

PostPosted: Thu Sep 29, 2005 14:12    Post subject: SQLQuery in a SQL Query while loop Reply with quote

Hi all,

First of all, let me thank you for your work.

I'm fairly new to nwnx and i want to execute something like this :

Code:

SQLExecDirect("SELECT player FROM pwdata");
while ( SQLFetch() == SQL_SUCCESS)
{
    SQLExecDirect("INSERT INTO `test` ( `player` ) VALUES ( '"+SQLGetData(1)+"' );
}


But actually, that doesn't work. SQL INSERT interrupts SELECT so my while loop stop working.

Is there any way of getting things like this work ?

PS : Sorry for my poor english i'm french
Back to top
View user's profile Send private message
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Thu Sep 29, 2005 22:28    Post subject: Reply with quote

Probably the simplest thing to do is a compound query like

"INSERT INTO test (player) SELECT player FROM pwdata"

but the data does not ever make it to the mod. I think one problem with this system is there is assumed one and only one statement active at a time, therefore you can not do what you are trying without saving the entire resultset first.
Back to top
View user's profile Send private message MSN Messenger
Kosmous



Joined: 10 Jan 2005
Posts: 44

PostPosted: Sat Oct 01, 2005 16:54    Post subject: Reply with quote

SQLExecDirect("SELECT player FROM pwdata");
while ( SQLFetch() == SQL_SUCCESS)
{
sPlayer = SQLGetData(1);
DelayCommand(1.0, SQLExecDirect("INSERT INTO `test` ( `player` ) VALUES ( '"+sPlayer+"' ));
}

simplest way to deal with this minor problem
Back to top
View user's profile Send private message
hacknisty



Joined: 27 Sep 2005
Posts: 2

PostPosted: Mon Oct 03, 2005 11:07    Post subject: Reply with quote

Many Thx KosMous !!! Smile) I would have never think it was so simple to workaround this little problem.

But i've got one more question :

Which minima is required for this type of query to work ?
It works fine with 1s but if I have 20 elements it would take 20 seconds to run ?

Is 0.2s delay work ?
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Mon Oct 03, 2005 15:40    Post subject: Reply with quote

Any "delay"shifts it out of the run and into the que, so yes, 0.2 seconds will work.

A minor warning: Beware stacking too many of these. At some point the DelayCommand que can no longer handle any more entries and will not store them. In my test module this happens at around 90 commands..... Note that this is 90 DelayCommands in the ENTIRE MODULE, not just the one script Crying or Very sad
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Oct 04, 2005 23:16    Post subject: Reply with quote

Among other reasons, this one made me create the hashset plugin. You can store resultsets quite efficiently there and then loop through it afterwards.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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