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 
 
Custom SetPersistentObject Function

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
RXKai



Joined: 10 Feb 2006
Posts: 2

PostPosted: Sat Feb 11, 2006 0:00    Post subject: Custom SetPersistentObject Function Reply with quote

Hey all, ive been writing my own set of functions to use with nwnx and im stumped at how to re-write SetPersistentObject to fit my database. This is the items table structure:

ItemID - Integer
ItemName - Varchar
ItemOwner - Integer (id of a player)
ItemQuantity - Integer
Item - Blob

I've written my own two functions utilizing this structure (they dont work lol). The items get stored in the database, but an error in the log about sql syntax appears, despite storing the objects correctly and my GetPersistentObject function just doesnt work at all. If anyone could post a sample for each of the functions id be greatful. Ill also post my own functions on request.
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sun Feb 12, 2006 20:46    Post subject: Reply with quote

Well, the working example is in aps_include... not sure what else you would like to see ? You could also post your log entries, maybe something can be seen from that.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
RXKai



Joined: 10 Feb 2006
Posts: 2

PostPosted: Sun Feb 12, 2006 23:07    Post subject: Reply with quote

Heres an example from the log when an item was put in the chest:

o Got request: INSERT INTO Items(ItemOwner, ItemName, ItemQuantity, Item) VALUES (7, 'Bolt +3', 99, ~s)
! 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 '~s)' at line 1

Here is my function for storing an object, maybe someone can look over it and say if i have an error anywhere: (I apologize for the length)

Code:

void SetPersistentPlayerObject(object oPC, string sField, object oObject)
{
        string sSQL;
        string sItemName = GetName(oObject);
        int nItemQuantity = GetItemStackSize(oObject);

        sSQL = "SELECT ItemOwner, ItemName, ItemQuantity FROM Items " +
        "WHERE ItemOwner = " + IntToString(GetCharID(oPC));

        if (SQL_SUCCESS == SQLFetch())
        {
            string sStoredItem = SQLGetData(2);
            int nStoredItemQuantity = StringToInt(SQLGetData(3));
            int nOwner = StringToInt(SQLGetData(1));

            // Is the item stackable
            if (GetNumStackedItems(oObject) >1 )
            {
                // Is the item allready stored.
                if (sStoredItem == sItemName && nOwner == GetCharID(oPC))
                {
                    // Item is stored and stackable, update its quantity
                    sSQL = "UPDATE Items SET ItemQuantity = " + IntToString(nItemQuantity) +
                    " WHERE ItemOwner = " + IntToString(GetCharID(oPC));
                    SQLExecDirect(sSQL);
                }
                else
                {
                    // Item isn't allready stored and is stackable
                    //Write a new entry for it.
                    sSQL = "INSERT INTO Items(ItemOwner, ItemName, ItemQuantity, Item) " +
                    "VALUES (" + IntToString(GetCharID(oPC)) + ", '" + GetName(oObject) + "', " + IntToString(nItemQuantity) + ", %s)";
                    SQLExecDirect(sSQL);

                    SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
                    StoreCampaignObject ("NWNX", "-", oObject);
                }
            }
            // Item isn't stackable. Write a new entry for it
            else
            {
                    sSQL = "INSERT INTO Items(ItemOwner, ItemName, ItemQuantity, Item) " +
                    "VALUES (" + IntToString(GetCharID(oPC)) + ", '" + GetName(oObject) + "', 1, %s)";
                    SQLExecDirect(sSQL);

                    SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
                     StoreCampaignObject ("NWNX", "-", oObject);
            }


        }
}
Back to top
View user's profile Send private message
Vladiat0r



Joined: 17 Jun 2005
Posts: 25

PostPosted: Mon Feb 13, 2006 3:44    Post subject: Reply with quote

If this is your table structure:
ItemID - Integer
ItemName - Varchar
ItemOwner - Integer (id of a player)
ItemQuantity - Integer
Item - Blob

Then in this statement the number of values doesn't match. Only 4 values here and the 4th is expected to be an Integer:
INSERT INTO Items(ItemOwner, ItemName, ItemQuantity, Item)

And the %s parameter is not getting replaced in your string, which gets turned into ~s
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules 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