View previous topic :: View next topic |
Author |
Message |
BelowTheBelt
Joined: 28 Jul 2010 Posts: 29
|
Posted: Wed Apr 09, 2014 17:06 Post subject: SQL returning blank string |
|
|
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 |
|
|
Terra_777
Joined: 27 Jun 2008 Posts: 216 Location: Sweden
|
Posted: Wed Apr 09, 2014 19:28 Post subject: |
|
|
Sounds like you need to run SQLInit on mod load. _________________ I dun have any signature, I'm happy anyway. |
|
Back to top |
|
|
BelowTheBelt
Joined: 28 Jul 2010 Posts: 29
|
Posted: Wed Apr 09, 2014 19:57 Post subject: |
|
|
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 |
|
|
BelowTheBelt
Joined: 28 Jul 2010 Posts: 29
|
Posted: Wed Apr 09, 2014 20:31 Post subject: |
|
|
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 |
|
|
|