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 
 
Apparent bug in 1.04 (GetPersistentInt)

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Morpheus



Joined: 18 Oct 2006
Posts: 39

PostPosted: Tue Nov 21, 2006 0:03    Post subject: Apparent bug in 1.04 (GetPersistentInt) Reply with quote

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


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Wed Nov 22, 2006 23:03    Post subject: Reply with quote

What do you get when you query the database with SQLExecDirect and GetData (i.e., without the convenience functions) ?
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Nov 22, 2006 23:36    Post subject: Re: Apparent bug in 1.04 Reply with quote

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



Joined: 18 Oct 2006
Posts: 39

PostPosted: Thu Nov 23, 2006 7:28    Post subject: Reply with quote

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



Joined: 02 Dec 2006
Posts: 1

PostPosted: Sat Dec 02, 2006 22:00    Post subject: GetPersistentInt - FAILED Reply with quote

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



Joined: 03 Dec 2006
Posts: 3

PostPosted: Sun Dec 03, 2006 1:35    Post subject: Reply with quote

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


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sun Dec 03, 2006 10:41    Post subject: Reply with quote

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



Joined: 18 Oct 2006
Posts: 39

PostPosted: Sat Dec 09, 2006 6:24    Post subject: Reply with quote

Hey guys! Sorry to have forgotten this but looks like you nailed it. Great work.
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Sat Dec 09, 2006 8:08    Post subject: Reply with quote

don't forget to correct this mistake in the version 1.07 ! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development 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