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 
 
NwNX4 1.09 andSet/GetPersistentObject

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Mon Dec 07, 2009 9:29    Post subject: NwNX4 1.09 andSet/GetPersistentObject Reply with quote

Hi, i'm have been reading the post about this, but not sure if i'm doing the thing correctly

I have this part for create the table
Code:
   if(!doesTableExist(sqliteDB_Antimagic_Item))
    {
        SQLExecDirect("CREATE TABLE "+  sqliteDB_Antimagic_Item +"(" +
            "player varchar(255) NOT NULL default '~'," +
         "tag varchar(255) NOT NULL default '~'," + 
         "name varchar(255) NOT NULL default '~'," +
         "val blob ," +
            "expire int(11) default NULL," +
            "last timestamp NOT NULL default current_timestamp," +
            "PRIMARY KEY (name)" +
            ")"
        );


Where sqliteDB_Antimagic_Item it's a const string

Second, im using directly the SetPeristentObject() function

Code:
SetPersistentObject(oPC, sKey,oItem, PersistentTime,sqliteDB_Antimagic_Item);


And this is the exit of the xp_sqlite.txt

Code:
* Executing: SELECT count(*) FROM antimagic_DB_PersistentItem
! SQL Error: no such table: antimagic_DB_PersistentItem
* Executing: CREATE TABLE antimagic_DB_PersistentItem(player varchar(255) NOT NULL default '~',tag varchar(255) NOT NULL default '~',name varchar(255) NOT NULL default '~',val blob ,expire int(11) default NULL,last timestamp NOT NULL default current_timestamp,PRIMARY KEY (name))
* Executing: SELECT count(*) FROM antimagic_DB_PersistentItem
* Returning: 0
* Executing: SELECT player FROM antimagic_DB_PersistentItem WHERE player='BelSirk' AND tag='Vens Waynn' AND name='SERVERVAULT:BelSirk\venswaynn_nw_it_mbelt018_25_14_1_6_1'
* Executing: COMMIT TRANSACTION;
* Executing: BEGIN TRANSACTION;


And with those are where i'm not sure if the script it's working or isn't it
because on other tables i put directly a Insert statment and appear on the log, checking the script from the nwnsql i found the Insert line it's already there but they are using SQLSCORCOExec(sSQL) and SQLStoreObject (oObject) instead of my clasic SQLEXecute(), so, not sure if those aren't working or the log don't register those instruction (something i doubt)

I already try with GetPeristentObject once i use SEtPersistentObject and nothing...
Back to top
View user's profile Send private message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Tue Dec 08, 2009 7:11    Post subject: Reply with quote

Ok, making again the search on the forum i found this topic :

Quote:
Posted: Sun Jan 20, 2008 14:45 Post subject: Reply with quote
Set/Get Object are (as yet) not included in NWNX4.
There is an 'alternative' nwnx4 that allows you to use 'original' style plugins in NWNX4, this may help.

However it's still a mute point as GetFirst/GetNext NWScripting functions in NWN2 don't work properly for inventories yet.

Cheers
Gryphyn


But have more than one year...

I just found this one http://www.nwnx.org/phpBB2/viewtopic.php?t=1425&highlight=setpersistentobject where he already solve his problem but i can't figure where is my error...

Another thing: the erf which come with the download file have those function:

Code:
void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =
                         0, string sTable = "pwobjdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oOwner))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
        sTag = SQLEncodeSpecialChars(GetName(oOwner));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oOwner);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
            " WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
        SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
}

object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
    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 + "'";
    SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);

    if (!GetIsObjectValid(oOwner))
        oOwner = oObject;
    return RetrieveCampaignObject ("NWNX", "-", GetLocation(oOwner), oOwner);
}


but searching on the forum found antoher erf which have those functions:
Code:
void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =
                         0, string sTable = "pwobjdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oOwner))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
        sTag = SQLEncodeSpecialChars(GetName(oOwner));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oOwner);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
            " WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SQLSCORCOExec(sSQL);
        SQLStoreObject (oObject);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
        SQLSCORCOExec(sSQL);
        SQLStoreObject (oObject);
    }
}

object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
    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 + "'";
    SQLSCORCOExec(sSQL);

    if (!GetIsObjectValid(oOwner))
        oOwner = oObject;
    return SQLRetrieveObject (GetLocation(oOwner), oOwner);
}


I'm assuming the second one it's the correct but neither of them work...

One last thing: i already try chaning my table declaration the one as the nwnx_include erf:
Code:
   if(!doesTableExist(sqliteDB_Antimagic_Item))
    {
        SQLExecDirect("CREATE TABLE "+  sqliteDB_Antimagic_Item +"(" +
         "player varchar(64) NOT NULL default '~'," +
           "tag varchar(64) NOT NULL default '~'," +
           "name varchar(255) NOT NULL default '~'," +
           "val blob," +
           "expire int(11) default NULL," +
           "last timestamp NOT NULL default current_timestamp," +
            "PRIMARY KEY (player,tag,name)" +
            ")"
        );
Back to top
View user's profile Send private message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Tue Dec 08, 2009 9:28    Post subject: Found the problem Reply with quote

Seem i was too tired when read _Mordred_ topic, the GetPeristentObject only work fine under MySQL
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Dec 08, 2009 9:40    Post subject: Reply with quote

My Quote was from BEFORE the hooks for SCORCO were found... Wink

This is the code from nwnx_sql.erf (from the SVN trunk)

Code:
void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =  0, string sTable = "pwobjdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oOwner))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
        sTag = SQLEncodeSpecialChars(GetName(oOwner));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oOwner);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
            " WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
        SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
}

object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
    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 + "'";
    SetLocalString(GetModule(), "NWNX!SQL!SETSCORCOSQL", sSQL);

    if (!GetIsObjectValid(oOwner))
        oOwner = oObject;
    return RetrieveCampaignObject ("NWNX", "-", GetLocation(oOwner), oOwner);
}


StoreCampainObject() and RetieveCampainObject() are the functions being hooked.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Tue Dec 08, 2009 10:07    Post subject: Reply with quote

ouch... then i need to rework the thing because i'm getting a error yet (now with MySQL) :




I have this for create the table
Code:
   if(!doesTableExist(sqliteDB_Antimagic_Item))
    {
        SQLExecDirect("CREATE TABLE "+  sqliteDB_Antimagic_Item +"(" +
         "player varchar(64) NOT NULL default '~'," +
           "tag varchar(64) NOT NULL default '~'," +
           "name varchar(255) NOT NULL default '~'," +
           "val text," +
           "expire int(11) default NULL," +
           "last timestamp NOT NULL default current_timestamp," +
            "PRIMARY KEY (player,tag,name)" +
            ")"+
         //MySQL line
         "ENGINE=MyISAM DEFAULT CHARSET=latin1;"
        );


And i have this simple example:

Code:
         SetPersistentObject(oPC, sKey,oItem, PersistentTime,sqliteDB_Antimagic_Item);      GetPersistentObject(oPC,sKey,OBJECT_INVALID,sqliteDB_Antimagic_Item);


Where again sqliteDB_Antimagic_Item it's a const string and sKey already pass by SQLEncodeSpecialChars and the result is this one:

Code:
* Executing: SELECT player FROM antimagic_DB_PersistentItem WHERE player='BelSirk' AND tag='Vens Waynn' AND name='SERVERVAULT:BelSirk\\\\venswaynn_NW_WSWMDG009_39_13_1_6_1'
* SCO query:
* RCO query:
* Executing: COMMIT TRANSACTION;
! SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TRANSACTION' at line 1 (1064).
* Executing: BEGIN TRANSACTION;
! SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TRANSACTION' at line 1 (1064).
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Dec 08, 2009 10:32    Post subject: Reply with quote

Belsirk,
This could take a while...

sqliteDB_Antimagic_Item = "antimagic_DB_PersistentItem"
which is your TABLE name. (a string)

SCO query seems to work,
RCO query seems to work, (to debug print the TAG of the retrieved object)

COMMIT TRANSACTION fails. (mySQL syntax)
--should be just "COMMIT" or "COMMIT WORK"

Cheers
Gryphyn
Back to top
View user's profile Send private message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Wed Dec 09, 2009 5:04    Post subject: Reply with quote

Gryphyn wrote:
Belsirk,
This could take a while...

sqliteDB_Antimagic_Item = "antimagic_DB_PersistentItem"
which is your TABLE name. (a string)

SCO query seems to work,
RCO query seems to work, (to debug print the TAG of the retrieved object)

COMMIT TRANSACTION fails. (mySQL syntax)
--should be just "COMMIT" or "COMMIT WORK"

Cheers
Gryphyn


Fixed the error i had with Commit and Begin ... but SCO and RCO still being on blanck and i'm not getting a valid item... (though with your older version the item was created )
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Dec 09, 2009 12:01    Post subject: Reply with quote

What type of objects are you storing?
MySQL has different BLOB types as you 'storage requirements increase'
Medium or Long BLOB may help (it item truncation is your problem)
Back to top
View user's profile Send private message
Belsirk



Joined: 04 Sep 2009
Posts: 16

PostPosted: Thu Dec 10, 2009 6:31    Post subject: Reply with quote

i'm trying to store items (Armor, shield, weapons ) and i already try with LONGBLOB and nothing, all the other code from my DB work fine on MySQL

Ok...

I used your old nwnx_sql.nss file and with that the things work fine... the table with the persistent item have a weight of 13.4 KB and the item retrieve with GetPersistentObject it's valid...

With the same code than before (Longblob though) but just changed the file i get this exit:

Code:
* Executing: SELECT player FROM antimagic_DB_PersistentItem WHERE player='BelSirk' AND tag='Vens Waynn' AND name='SERVERVAULT:BelSirk\\\\venswaynn_NW_MAARCL046_14_13_1_6_1'
* SCO query: INSERT INTO antimagic_DB_PersistentItem (player,tag,name,val,expire) VALUES('BelSirk','Vens Waynn','SERVERVAULT:BelSirk\\\\venswaynn_NW_MAARCL046_14_13_1_6_1',%s,0)
* RCO query: SELECT val FROM antimagic_DB_PersistentItem WHERE player='BelSirk' AND tag='Vens Waynn' AND name='SERVERVAULT:BelSirk\\\\venswaynn_NW_MAARCL046_14_13_1_6_1'
*
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
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