View previous topic :: View next topic |
Author |
Message |
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Tue Nov 21, 2006 0:03 Post subject: Apparent bug in 1.04 (GetPersistentInt) |
|
|
Hi,
I'm having some odd behavior using MySQL 5 with NWNX4 v1.04. I call SetPersistentInt and it sets the value fine, but GetPersistentInt seems to only return 1 if the variable is present and 0 if it is not. I verify this by calling getpersistentint in my game and display the result, then manually change the value in the database to something like 5 and it still returns 1. Even when the value is 0 it returns 1, but if I remove the row, it then returns 0.
Morph |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Wed Nov 22, 2006 23:03 Post subject: |
|
|
What do you get when you query the database with SQLExecDirect and GetData (i.e., without the convenience functions) ? _________________ Papillon |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Wed Nov 22, 2006 23:36 Post subject: Re: Apparent bug in 1.04 |
|
|
Morpheus wrote: | Hi,
I'm having some odd behavior using MySQL 5 with NWNX4 v1.04. I call SetPersistentInt and it sets the value fine, but GetPersistentInt seems to only return 1 if the variable is present and 0 if it is not. I verify this by calling getpersistentint in my game and display the result, then manually change the value in the database to something like 5 and it still returns 1. Even when the value is 0 it returns 1, but if I remove the row, it then returns 0.
Morph |
Something I noticed in the toolset (which is new to NWN2) is that there are two types of INT's now (signed & unsigned) - could this have something to do with it?
Cheers
Gryphyn |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Thu Nov 23, 2006 7:28 Post subject: |
|
|
Papillon wrote: | What do you get when you query the database with SQLExecDirect and GetData (i.e., without the convenience functions) ? |
Let me try that and report back. |
|
Back to top |
|
|
SumoSake
Joined: 02 Dec 2006 Posts: 1
|
Posted: Sat Dec 02, 2006 22:00 Post subject: GetPersistentInt - FAILED |
|
|
I currently have this same issue... NWNX4 1.06 and MySQL 4.0.
SetPersistentInt works fine but GetPersistentInt always returns a "1".
This topic is over a week old, just wondering if Morpheus found a solution/or tested by not using the convenience functions.
Thanks |
|
Back to top |
|
|
radsam
Joined: 03 Dec 2006 Posts: 3
|
Posted: Sun Dec 03, 2006 1:35 Post subject: |
|
|
Hey all,
I just ran into the same problem and have found the cause
here's the code from the 1.06's GetPersistantInt:
Code: | int GetPersistentInt(object oObject, string sVarName, string sTable = "pwdata")
{
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
oModule = GetModule();
SetLocalString(oModule, "NWNX!SQL!FETCH", "-2147483647");
return StringToInt(GetLocalString(oModule, "NWNX!SQL!FETCH"));
}
|
Pay attention to the last 4 lines:
"NWNX!SQL!FETCH" mod variable location is used in SQLFetch() function as a SQL_SUCCESS(1) or SQL_ERROR(0) flag holder for the execution of the last SQL command.
Also, the GetPersistantString() function (that works) uses a different method for retrieving the data from the database, here's the same code area excerpt
Code: | ...
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
return SQLGetData(1);
else
{
return "";
}
... |
so anyway, replacing the last 3 lines of code in GetPersistantInt() with the code below will give you the right data
Code: | //if SQL command was successful
if (SQLFetch() == SQL_SUCCESS)
//return the retrieved value
return StringToInt(SQLGetData(1));
else
//command failed, return default value
return 0; |
here's the replacement code for the GetPersistentFloat function:
Code: | //if SQL command was successful
if (SQLFetch() == SQL_SUCCESS)
//return the retrieved value
return StringToFloat(SQLGetData(1));
else
//command failed, return default value
return 0.0; |
this works for me, would be great is someone can verify this to save Papillon some debugging time.
-RaDSaM |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Sun Dec 03, 2006 10:41 Post subject: |
|
|
*Slaps forehead* Of course. SQLFetch does not retrieve the row like in NWNX2, it just advances the resultset to the next row internally, so SQLGetData is necessary afterwards.
Good find! _________________ Papillon |
|
Back to top |
|
|
Morpheus
Joined: 18 Oct 2006 Posts: 39
|
Posted: Sat Dec 09, 2006 6:24 Post subject: |
|
|
Hey guys! Sorry to have forgotten this but looks like you nailed it. Great work. |
|
Back to top |
|
|
caloup
Joined: 29 Sep 2006 Posts: 59 Location: albi (france)
|
Posted: Sat Dec 09, 2006 8:08 Post subject: |
|
|
don't forget to correct this mistake in the version 1.07 ! |
|
Back to top |
|
|
|