View previous topic :: View next topic |
Author |
Message |
hacknisty
Joined: 27 Sep 2005 Posts: 2
|
Posted: Thu Sep 29, 2005 14:12 Post subject: SQLQuery in a SQL Query while loop |
|
|
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 |
|
|
odenien
Joined: 26 Sep 2005 Posts: 37
|
Posted: Thu Sep 29, 2005 22:28 Post subject: |
|
|
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 |
|
|
Kosmous
Joined: 10 Jan 2005 Posts: 44
|
Posted: Sat Oct 01, 2005 16:54 Post subject: |
|
|
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 |
|
|
hacknisty
Joined: 27 Sep 2005 Posts: 2
|
Posted: Mon Oct 03, 2005 11:07 Post subject: |
|
|
Many Thx KosMous !!! ) 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 |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Mon Oct 03, 2005 15:40 Post subject: |
|
|
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 |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue Oct 04, 2005 23:16 Post subject: |
|
|
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 |
|
|
|