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 
 
haveing a problem getting data into the database

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
raistlinmajere



Joined: 15 Feb 2006
Posts: 3

PostPosted: Sat Feb 18, 2006 16:54    Post subject: haveing a problem getting data into the database Reply with quote

i am trying to get the database o recognize this
Code:

void SetSubraceDBInt(string sCampaignName, string sVarName, int nInt, object oPlayer=OBJECT_INVALID)
{
    string sPlayer;
    string sTag;
    if (GetIsPC(oPlayer))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPlayer));
        sTag = SQLEncodeSpecialChars(GetName(oPlayer));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oPlayer);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);
    string sValue = IntToString(nInt);

    string sSQL = "SELECT player FROM '" + SUBRACE_DATABASE + "' WHERE player='" + sPlayer +
                  "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);
    if (SQLFirstRow() == SQL_SUCCESS)
    {
        sSQL = "UPDATE '" + SUBRACE_DATABASE + "' SET val='" + sValue + "',expire=0 WHERE player='"+ sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SQLExecDirect(sSQL);
    }
    else
    {
        sSQL = "INSERT INTO '" + SUBRACE_DATABASE + "' (player,tag,name,val,expire) VALUES" +
               "('" + sPlayer + "','" + sTag + "','" + sVarName + "','" + sValue + "',0)";
        SQLExecDirect(sSQL);
    }
}
int GetSubraceDBInt(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{
    string sPlayer;
    string sTag;
    if (GetIsPC(oPlayer))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPlayer));
        sTag = SQLEncodeSpecialChars(GetName(oPlayer));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oPlayer);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);
    string sSQL = "SELECT val FROM '" + SUBRACE_DATABASE + "' WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);
    if (SQLFirstRow() == SQL_SUCCESS)
    {
        return StringToInt(SQLGetData(1));
    }
    else
    {
        return StringToInt("0");
    }
}

but in the error logs this keeps comeing back
Quote:

o Got request: SELECT val FROM 'SUBRACE_DB' WHERE player='vendaarie' AND tag='Hastant' AND name='SBRCE_centaur'
! 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 ''SUBRACE_DB' WHERE player='vendaarie' AND tag='Hastant' AND name='SBRCE_centaur'' at line 1
o Empty set

the SUBRACE_DB is the table im useing for my subrace info its exactly the same as the pwdata from the asp_demo.mod any suggestions ?
Back to top
View user's profile Send private message
Dazzle



Joined: 29 Dec 2004
Posts: 19

PostPosted: Sat Feb 18, 2006 20:08    Post subject: Reply with quote

Try removing the ' ' around SUBRACE_DATABASE.
Back to top
View user's profile Send private message
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Mon Feb 20, 2006 14:43    Post subject: Reply with quote

If you use quotes around database objects they should be the double quotes. Single quotes are used for identifying string data.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related 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