View previous topic :: View next topic |
Author |
Message |
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Fri Jun 01, 2007 2:49 Post subject: Not getting all rows back |
|
|
Hi,
I have a complex query that I run in game and a while(SQLFetch()==SQL_SUCCESS) that prints out all the rows. it only prints the first row, but when I cut/paste the SQL from the log into mysql client, it returns the 4 rows I expect.
I am using 1.07. Here is the query, FWIW.
select rank,parent,thetext,state,next,pwms_quests_conv.conditions,actions,quest,pwms_quests_conv.guid,anycond,speaker,nwn1,pwms_quests.tag from pwms_quests_conv,pwms_quests where speaker='NPC_ORC' and pwms_quests.guid='71475446-25f1-4327-93dd-d9305361c764' and pwms_quests.guid=pwms_quests_conv.quest and parent<0
In NWNX it returns 1 row. In MySQL client on same data, it returns the correct amount.
Any ideas?
Morph |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Fri Jun 01, 2007 4:32 Post subject: |
|
|
could you paste your script/loop in here? _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sat Jun 02, 2007 2:36 Post subject: |
|
|
I think I found the reason, but not sure of a fix.
I have a while loop while(SQLFetch()==SQL_SUCCESS) { } and inside the while loop I do another SQLExecDirect, and I think it causes the outside check to fail.
Any suggested workarounds for this?
thanks!!
Morph |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Jun 02, 2007 5:45 Post subject: |
|
|
Morpheus wrote: | I think I found the reason, but not sure of a fix.
I have a while loop while(SQLFetch()==SQL_SUCCESS) { } and inside the while loop I do another SQLExecDirect, and I think it causes the outside check to fail.
Any suggested workarounds for this?
thanks!!
Morph |
You can wait for 1.06 (the real one), and then the SQLServer plugin.
The new one's going to have MARS support (blame M$ for the name)
but in the interim - is the 'inner' SQLExecDirect required? - could a restructured 'outer' query get the same result?
Or would it be possible to do all the work in the database using a procedure?
Cheers
Gryphyn |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Sat Jun 02, 2007 11:56 Post subject: |
|
|
You can have a SQLExecDirect in the inner loop in NWNX4, but it may not return results, i.e. only INSERT and UPDATE. Otherwise, the "outer" result set will be overwritten.
If you need two resultsets, here's a quick workaround: Duplicate your plugin DLL and INI file, rename the function class of the second plugin, and then you can use two seperate connections to your database, which are completely independent of each other. _________________ Papillon |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sat Jun 02, 2007 15:45 Post subject: |
|
|
Egads!
Papillon, would it be possible to allow multiple result sets by using a key like this?
SQLExecDirect("select...","key");
SQLFetch("key");
to separate the different sets and nwnx would just use an internal hash to maintain them?
EDIT:
The workaround I am doing is just reading the outer set into a tokenized string first, then iterating over that and doing my other selects then.
Morph
Last edited by Morpheus on Sat Jun 02, 2007 16:06; edited 1 time in total |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sat Jun 02, 2007 15:45 Post subject: |
|
|
Gryphyn wrote: | Morpheus wrote: | I think I found the reason, but not sure of a fix.
I have a while loop while(SQLFetch()==SQL_SUCCESS) { } and inside the while loop I do another SQLExecDirect, and I think it causes the outside check to fail.
Any suggested workarounds for this?
thanks!!
Morph |
You can wait for 1.06 (the real one), and then the SQLServer plugin.
The new one's going to have MARS support (blame M$ for the name)
but in the interim - is the 'inner' SQLExecDirect required? - could a restructured 'outer' query get the same result?
Or would it be possible to do all the work in the database using a procedure?
Cheers
Gryphyn |
What SQLServer plugin? |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Sat Jun 02, 2007 16:23 Post subject: |
|
|
@Morpheus: Multiple resultsets would be possible, but nobody has gotten around to provide a working implementation yet. It has often been said how easy a DB plugin supporting multiple resultsets would be, but nobody has actually presented one.
There are currently no plans to extend the plugins in that direction, as far as I am concerned. Sorry _________________ Papillon |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sat Jun 02, 2007 19:32 Post subject: |
|
|
Hmmmm. In theory it could be done (although less efficient) on the script side. Like I was able to read my result set into a tokenized string that I later iterate over almost the same way as a sqlfetch(). So the resultset can be read in and associated with a key in yet another tokenized string.
SQLFetch would not be needed then, but it could work like this:
SQLExecDirect("select ....","key1");
SQLExecDirect("select ....","key2");
string value = SQLGetData(1,"key1");
string value2 = SQLGetData(1,"key2");
SQLClose(); // New function to flush out the key'd arrays.
This would be very doable on the script side of things. Maybe I will write a wrapper script to do it.
Morph |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Sat Jun 02, 2007 23:18 Post subject: |
|
|
I had plans to implement multiple resultsets in NWNX-ODBC, but I found out that in most cases it's possible to get rid of queries in the cycle with JOIN in the main query. |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sun Jun 03, 2007 2:09 Post subject: |
|
|
Yeah, but those exceptions are the tricky parts! |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Sun Jun 03, 2007 2:32 Post subject: |
|
|
virusman wrote: | I had plans to implement multiple resultsets in NWNX-ODBC, but I found out that in most cases it's possible to get rid of queries in the cycle with JOIN in the main query. |
That was going to be my suggestion as well. Usually nested queries can be combined into a single query; and failing that, I think mysql now supports subselects. EIther one will also be faster than nested queries in nwscript _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sun Jun 03, 2007 5:57 Post subject: |
|
|
In my case its not possible to combine, because data retrieved from the first query is used to issue a second query and depending on the second result the loop will bail and doesn't need to do any more lookups. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sun Jun 03, 2007 9:52 Post subject: |
|
|
Morpheus wrote: | What SQLServer plugin? |
--Have a look here *based on ODBC
Now that I've finally sorted out my NWN2/Vista issues a SQLServer (1.08+) version won't be long in development.
With the (new) 1.08 NWScript hooks I was looking at using the 'int' parameter to manage 'connections'.
"0" was going to be a connection to the "master" database, any others would be from the connection details provided in the ini file. (created on request)
I'm still investigating the MARS functionality but apparently this lets you do the same thing in a single connection. Not sure yet how to implement it.
Cheers
Gryphyn |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Sun Jun 03, 2007 15:46 Post subject: |
|
|
Gryphyn wrote: | Morpheus wrote: | What SQLServer plugin? |
--Have a look here *based on ODBC
Now that I've finally sorted out my NWN2/Vista issues a SQLServer (1.08+) version won't be long in development.
With the (new) 1.08 NWScript hooks I was looking at using the 'int' parameter to manage 'connections'.
"0" was going to be a connection to the "master" database, any others would be from the connection details provided in the ini file. (created on request)
I'm still investigating the MARS functionality but apparently this lets you do the same thing in a single connection. Not sure yet how to implement it.
Cheers
Gryphyn |
Might want to be careful though -- by doing that any code that uses the SQL server plugin becomes incompatible with the "standard" API for SQL plugins. _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
|