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 
 
Not getting all rows back
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Fri Jun 01, 2007 2:49    Post subject: Not getting all rows back Reply with quote

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
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Fri Jun 01, 2007 4:32    Post subject: Reply with quote

could you paste your script/loop in here?
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sat Jun 02, 2007 2:36    Post subject: Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Jun 02, 2007 5:45    Post subject: Reply with quote

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. Very Happy
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
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sat Jun 02, 2007 11:56    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sat Jun 02, 2007 15:45    Post subject: Reply with quote

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
View user's profile Send private message
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sat Jun 02, 2007 15:45    Post subject: Reply with quote

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. Very Happy
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
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sat Jun 02, 2007 16:23    Post subject: Reply with quote

@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 Smile
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sat Jun 02, 2007 19:32    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sat Jun 02, 2007 23:18    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sun Jun 03, 2007 2:09    Post subject: Reply with quote

Yeah, but those exceptions are the tricky parts! Smile
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sun Jun 03, 2007 2:32    Post subject: Reply with quote

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
View user's profile Send private message
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sun Jun 03, 2007 5:57    Post subject: Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sun Jun 03, 2007 9:52    Post subject: Reply with quote

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
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sun Jun 03, 2007 15:46    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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