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 
 
SQL returning blank string

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support
View previous topic :: View next topic  
Author Message
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Apr 09, 2014 17:06    Post subject: SQL returning blank string Reply with quote

So I'm playing around with random tables. I'm first starting with a simple encounter table (sg_002). 2 columns: Probability (float) and ResRef (varchar).

There's approx 30 rows of probabilities and resrefs along the lines of:

Probability ResRef
8.05 nw_bandit004
8.00 nw_bandit001
8.00 nw_bandit002
8.00 nw_gypsy002
6.00 nw_bandit003
5.00 nw_bugbearb
4.00 zep_beetlestagf
3.00 nw_humanmerc001
3.00 nw_ratdire001
3.00 zep_beetleslict
3.00 zep_beetlespitt

The sum of all the probabilities = 100.00

In my spawn script, I have the following function to return the ResRef:

Code:
string SQLGetSpawn(string SpawnGroupNumber)
{
string sSQL ="SELECT ResRef FROM sg_002 ORDER BY -LOG(RAND())/Probability ASC LIMIT 1";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_ERROR)
    {
    WriteTimestampedLogEntry("ERROR : database unable to resolve ResRef.");
    return "";
    }
return SQLGetData(2);
}


When I test the SQL in my SQL app it returns the correct resrefs. When I look in my ODBC logs, it shows that it is returning correct resrefs. Addititionally, there are no error logs resulting from SQLFetch().

However, when I get in-game, it shows that the spawn system is getting a blank string (i.e. the spawn script shows the return value from SQLGetData(2) = "", rather than the resref shown in my ODBC log).

Any thoughts as to what might be going wrong?

Thanks!
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Wed Apr 09, 2014 19:28    Post subject: Reply with quote

Sounds like you need to run SQLInit on mod load.
_________________
I dun have any signature, I'm happy anyway.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Apr 09, 2014 19:57    Post subject: Reply with quote

Good place to start, but unfortunately, it's not that simple. I'm running SQLInit(); already on load first thing.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Apr 09, 2014 20:31    Post subject: Reply with quote

I should've noticed this when testing the SQL, but the result set only has 1 column, so by changing the return SQLGetData(2) to SQLGetData(1), it fixed the problem.

For some reason, I was thinking that the result set still had 2 columns.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support 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