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 
 
NWServer crash on SQLFetch

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Primogenitor



Joined: 08 Jan 2005
Posts: 88

PostPosted: Mon Mar 21, 2005 13:06    Post subject: NWServer crash on SQLFetch Reply with quote

For the ConvoCC Im caching 2da things in the database so I can do SQL queries to pull data out faster. However, I seem to have narrowed down a bug that doesnt make much sense.

All the 2da queries go through this function:
Code:

#include "prc_inc_switch"
#include "inc_utility"

const int PRC_SQL_ERROR = 0;
const int PRC_SQL_SUCCESS = 1;

string Get2DACache(string s2DA, string sColumn, int nRow);
void PRC_SQLInit();
void PRC_SQLExecDirect(string sSQL);
int PRC_SQLFetch();
string PRC_SQLGetData(int iCol);

void PRC_SQLInit()
{
    int i;

    // Placeholder for ODBC persistence
    string sMemory;

    for (i = 0; i < 8; i++)     // reserve 8*128 bytes
        sMemory +=
            "................................................................................................................................";

    SetLocalString(GetModule(), "NWNX!ODBC!SPACER", sMemory);
}

void PRC_SQLExecDirect(string sSQL)
{
PrintString(sSQL);
    SetLocalString(GetModule(), "NWNX!ODBC!EXEC", sSQL);
}

int PRC_SQLFetch()
{
    string sRow;
    object oModule = GetModule();

    SetLocalString(oModule, "NWNX!ODBC!FETCH", GetLocalString(oModule, "NWNX!ODBC!SPACER"));
    sRow = GetLocalString(oModule, "NWNX!ODBC!FETCH");
    if (GetStringLength(sRow) > 0)
    {
        SetLocalString(oModule, "NWNX_ODBC_CurrentRow", sRow);
        return PRC_SQL_SUCCESS;
    }
    else
    {
        SetLocalString(oModule, "NWNX_ODBC_CurrentRow", "");
        return PRC_SQL_ERROR;
    }
}

string PRC_SQLGetData(int iCol)
{
    int iPos;
    string sResultSet = GetLocalString(GetModule(), "NWNX_ODBC_CurrentRow");

    // find column in current row
    int iCount = 0;
    string sColValue = "";

    iPos = FindSubString(sResultSet, "¬");
    if ((iPos == -1) && (iCol == 1))
    {
        // only one column, return value immediately
        sColValue = sResultSet;
    }
    else if (iPos == -1)
    {
        // only one column but requested column > 1
        sColValue = "";
    }
    else
    {
        // loop through columns until found
        while (iCount != iCol)
        {
            iCount++;
            if (iCount == iCol)
                sColValue = GetStringLeft(sResultSet, iPos);
            else
            {
                sResultSet = GetStringRight(sResultSet, GetStringLength(sResultSet) - iPos - 1);
                iPos = FindSubString(sResultSet, "¬");
            }

            // special case: last column in row
            if (iPos == -1)
                iPos = GetStringLength(sResultSet);
        }
    }

    return sColValue;
}

void PRCMakeTables()
{
    string SQL;
    SQL = "cached2da_feat ( ";
    SQL+= "rowid int(55),";
    SQL+= "LABEL varchar(255),";
    SQL+= "FEAT varchar(255),";
    SQL+= "DESCRIPTION varchar(255),";
    SQL+= "ICON varchar(255),";
    SQL+= "MINATTACKBONUS varchar(255),";
    SQL+= "MINSTR varchar(255),";
    SQL+= "MINDEX varchar(255),";
    SQL+= "MININT varchar(255),";
    SQL+= "MINWIS varchar(255),";
    SQL+= "MINCON varchar(255),";
    SQL+= "MINCHA varchar(255),";
    SQL+= "MINSPELLLVL varchar(255),";
    SQL+= "PREREQFEAT1 varchar(255),";
    SQL+= "PREREQFEAT2 varchar(255),";
    SQL+= "GAINMULTIPLE varchar(255),";
    SQL+= "EFFECTSSTACK varchar(255),";
    SQL+= "ALLCLASSESCANUSE varchar(255),";
    SQL+= "CATEGORY varchar(255),";
    SQL+= "MAXCR varchar(255),";
    SQL+= "SPELLID varchar(255),";
    SQL+= "SUCCESSOR varchar(255),";
    SQL+= "CRValue varchar(255),";
    SQL+= "USESPERDAY varchar(255),";
    SQL+= "MASTERFEAT varchar(255),";
    SQL+= "TARGETSELF varchar(255),";
    SQL+= "OrReqFeat0 varchar(255),";
    SQL+= "OrReqFeat1 varchar(255),";
    SQL+= "OrReqFeat2 varchar(255),";
    SQL+= "OrReqFeat3 varchar(255),";
    SQL+= "OrReqFeat4 varchar(255),";
    SQL+= "REQSKILL varchar(255),";
    SQL+= "ReqSkillMinRanks varchar(255),";
    SQL+= "REQSKILL2 varchar(255),";
    SQL+= "ReqSkillMinRanks2 varchar(255),";
    SQL+= "Constant varchar(255),";
    SQL+= "TOOLSCATEGORIES varchar(255),";
    SQL+= "HostileFeat varchar(255),";
    SQL+= "MinLevel varchar(255),";
    SQL+= "MinLevelClass varchar(255),";
    SQL+= "MaxLevel varchar(255),";
    SQL+= "MinFortSave varchar(255),";
    SQL+= "PreReqEpic varchar(255)";
    SQL+= ")";
    SQL = "CREATE TABLE "+GetStringLowerCase(SQL);
    PRC_SQLExecDirect(SQL);

    SQL = "cached2da_soundset ( ";
    SQL+= "rowid int(55),";
    SQL+= "LABEL varchar(255), ";
    SQL+= "RESREF varchar(255), ";
    SQL+= "STRREF varchar(255), ";
    SQL+= "GENDER varchar(255), ";
    SQL+= "TYPE varchar(255) )";
    SQL = "CREATE TABLE "+GetStringLowerCase(SQL);
    SQL = "cached2da_portraits ( ";
    SQL+= "rowid int(255),";
    SQL+= "BaseResRef varchar(255), ";
    SQL+= "Sex varchar(255), ";
    SQL+= "Race varchar(255), ";
    SQL+= "InanimateType varchar(255), ";
    SQL+= "Plot varchar(255), ";
    SQL+= "LowGore varchar(255) )";
    SQL = "CREATE TABLE "+GetStringLowerCase(SQL);
    PRC_SQLExecDirect(SQL);

    SQL = "cached2da_appearance ( ";
    SQL+= "rowid int(55),";
    SQL+= "LABEL varchar(255), ";
    SQL+= "STRING_REF varchar(255), ";
    SQL+= "NAME varchar(255), ";
    SQL+= "RACE varchar(255), ";
    SQL+= "ENVMAP  varchar(255), ";
    SQL+= "BLOODCOLOR varchar(255), ";
    SQL+= "MODELTYPE varchar(255), ";
    SQL+= "WEAPONSCALE varchar(255), ";
    SQL+= "WING_TAIL_SCALE varchar(255), ";
    SQL+= "HELMET_SCALE_M varchar(255), ";
    SQL+= "HELMET_SCALE_F varchar(255), ";
    SQL+= "MOVERATE varchar(255), ";
    SQL+= "WALKDIST varchar(255), ";
    SQL+= "RUNDIST varchar(255), ";
    SQL+= "PERSPACE varchar(255), ";
    SQL+= "CREPERSPACE varchar(255), ";
    SQL+= "HEIGHT varchar(255), ";
    SQL+= "HITDIST varchar(255), ";
    SQL+= "PREFATCKDIST varchar(255), ";
    SQL+= "TARGETHEIGHT varchar(255), ";
    SQL+= "ABORTONPARRY varchar(255), ";
    SQL+= "RACIALTYPE varchar(255), ";
    SQL+= "HASLEGS varchar(255), ";
    SQL+= "HASARMS varchar(255), ";
    SQL+= "PORTRAIT varchar(255), ";
    SQL+= "SIZECATEGORY varchar(255), ";
    SQL+= "PERCEPTIONDIST varchar(255), ";
    SQL+= "FOOTSTEPTYPE varchar(255), ";
    SQL+= "SOUNDAPPTYPE varchar(255), ";
    SQL+= "HEADTRACK varchar(255), ";
    SQL+= "HEAD_ARC_H varchar(255), ";
    SQL+= "HEAD_ARC_V varchar(255), ";
    SQL+= "HEAD_NAME varchar(255), ";
    SQL+= "BODY_BAG varchar(255), ";
    SQL+= "TARGETABLE  varchar(255)";
    SQL+= ")";
    SQL = "CREATE TABLE "+GetStringLowerCase(SQL);
    PRC_SQLExecDirect(SQL);

    SQL = "cached2da_spells ( ";
    SQL+= "rowid int(55),";
    SQL+= "Label varchar(255), ";
    SQL+= "Name varchar(255), ";
    SQL+= "IconResRef varchar(255), ";
    SQL+= "School varchar(255), ";
    SQL+= "Range varchar(255), ";
    SQL+= "VS varchar(255), ";
    SQL+= "MetaMagic varchar(255), ";
    SQL+= "TargetType varchar(255), ";
    SQL+= "ImpactScript varchar(255), ";
    SQL+= "Bard varchar(255), ";
    SQL+= "Cleric varchar(255), ";
    SQL+= "Druid varchar(255), ";
    SQL+= "Paladin varchar(255), ";
    SQL+= "Ranger varchar(255), ";
    SQL+= "WizzSorc varchar(255), ";
    SQL+= "Innate varchar(255), ";
    SQL+= "ConjTime varchar(255), ";
    SQL+= "ConjAnim varchar(255), ";
    SQL+= "ConjHeadVisual varchar(255), ";
    SQL+= "ConjHandVisual varchar(255), ";
    SQL+= "ConjGrndVisual varchar(255), ";
    SQL+= "ConjSoundVFX varchar(255), ";
    SQL+= "ConjSoundMale varchar(255), ";
    SQL+= "ConjSoundFemale varchar(255), ";
    SQL+= "CastAnim varchar(255), ";
    SQL+= "CastTime varchar(255), ";
    SQL+= "CastHeadVisual varchar(255), ";
    SQL+= "CastHandVisual varchar(255), ";
    SQL+= "CastGrndVisual varchar(255), ";
    SQL+= "CastSound varchar(255), ";
    SQL+= "Proj varchar(255), ";
    SQL+= "ProjModel varchar(255), ";
    SQL+= "ProjType varchar(255), ";
    SQL+= "ProjSpwnPoint varchar(255), ";
    SQL+= "ProjSound varchar(255), ";
    SQL+= "ProjOrientation varchar(255), ";
    SQL+= "ImmunityType varchar(255), ";
    SQL+= "ItemImmunity varchar(255), ";
    SQL+= "SubRadSpell1 varchar(255), ";
    SQL+= "SubRadSpell2 varchar(255), ";
    SQL+= "SubRadSpell3 varchar(255), ";
    SQL+= "SubRadSpell4 varchar(255), ";
    SQL+= "SubRadSpell5 varchar(255), ";
    SQL+= "Category varchar(255), ";
    SQL+= "Master varchar(255), ";
    SQL+= "UserType varchar(255), ";
    SQL+= "SpellDesc varchar(255), ";
    SQL+= "UseConcentration varchar(255), ";
    SQL+= "SpontaneouslyCast varchar(255), ";
    SQL+= "AltMessage varchar(255), ";
    SQL+= "HostileSetting varchar(255), ";
    SQL+= "FeatID varchar(255), ";
    SQL+= "Counter1 varchar(255), ";
    SQL+= "Counter2 varchar(255), ";
    SQL+= "HasProjectile varchar(255))";
    SQL = "CREATE TABLE "+GetStringLowerCase(SQL);
    PRC_SQLExecDirect(SQL);

    SQL = "CREATE TABLE cached2da_cls_feat ( ";
    SQL+= "rowid int(55),";
    SQL+= "class varchar(255), ";
    SQL+= "FeatLabel varchar(255), ";
    SQL+= "FeatIndex varchar(255), ";
    SQL+= "List varchar(255), ";
    SQL+= "GrantedOnLevel varchar(255), ";
    SQL+= "OnMenu varchar(255))";
    PRC_SQLExecDirect(SQL);

    SQL = "CREATE TABLE cached2da ( file varchar(255), column varchar(255), rowid int(55), data varchar(255) )";
    PRC_SQLExecDirect(SQL);

}

string Get2DACache(string s2DA, string sColumn, int nRow)
{
    //get the waypoint htat marks the cache
    object oCacheWP = GetObjectByTag("CACHEWP");
    location lCache = GetLocation(oCacheWP);
    //if no waypoiint, use module start
    if (!GetIsObjectValid(oCacheWP))
        lCache = GetStartingLocation();
    //get the waypoint for this file
    string sFileWPName = "CACHED_"+GetStringUpperCase(s2DA)+"_"+sColumn+"_"+IntToString(nRow/1000);
    object oFileWP = GetWaypointByTag(sFileWPName);
    if (!GetIsObjectValid(oFileWP))
        oFileWP = CreateObject(OBJECT_TYPE_WAYPOINT,"NW_WAYPOINT001",lCache,FALSE,sFileWPName);
    string s = GetLocalString(oFileWP, "2DA_"+s2DA+"_"+sColumn+"_"+IntToString(nRow));
    //check if we should use the database
    int nDB = GetPRCSwitch(PRC_USE_DATABASE);
    string SQL;
    //lower case the 2da and column
    s2DA = GetStringLowerCase(s2DA);
    sColumn = GetStringLowerCase(sColumn);
   
    //sColumn = ReplaceChars(sColumn, "_" , "z");
    string sDBColumn = sColumn;
     
    //if its not locally cached already
    if (s == "")
    {
        //check the database
        if(nDB)
        {
            //initialize if needed
            if(GetLocalString(GetModule(), "NWNX!ODBC!SPACER") == "")
                PRC_SQLInit();
            if(s2DA == "feat"
                || s2DA == "spells"
                || s2DA == "portraits"
                || s2DA == "soundsets"
                || s2DA == "appearance"
                || s2DA == "rig")
                SQL = "SELECT "+sDBColumn+" FROM cached2da_"+s2DA+" WHERE ( rowid = "+IntToString(nRow)+" )";
            else if(TestStringAgainstPattern("cls_feat_**", s2DA))
                SQL = "SELECT "+sDBColumn+" FROM cached2da_cls_feat WHERE ( rowid = "+IntToString(nRow)+" ) AND ( file = '"+s2DA+"' )";
            else
                SQL = "SELECT data FROM cached2da WHERE ( file = '"+s2DA+"' ) AND ( column = '"+sDBColumn+"' ) AND ( rowid = "+IntToString(nRow)+" )";
           
            PRC_SQLExecDirect(SQL);
            // if there is an error, table is not built or is not initialized
           
//THIS IS THE LINE CAUSING A PROBLEM
            //if(PRC_SQLFetch() == PRC_SQL_ERROR)
            if(FALSE)
            {
                WriteTimestampedLogEntry("Error getting table from DB");
            }
            else
            {
                //table exists, and no problems accessing it
                s = PRC_SQLGetData(1);
            }
        }
        //entry didnt exist in the database
        if(s == "")
        {
            //fetch from the 2da file
            s = Get2DAString(s2DA, sColumn, nRow);
            if (s == "")
                s = "****";
            if(nDB)
            {
                //store it in the database
                //use specific tables for certain 2das
                if(s2DA == "feat"
                    || s2DA == "spells"
                    || s2DA == "portraits"
                    || s2DA == "soundset"
                    || s2DA == "appearance"
                    || s2DA == "rig")
                {
                    //check that 2da row exisits
                    SQL = "SELECT rowid FROM cached2da_"+s2DA+" WHERE rowid="+IntToString(nRow);
                    PRC_SQLExecDirect(SQL);
                    //if the row exists, then update it
                    //otherwise insert a new row
                    if(PRC_SQLFetch() == PRC_SQL_SUCCESS
                        && PRC_SQLGetData(1) != "")
                    {
                        SQL = "UPDATE cached2da_"+s2DA+" SET  "+sDBColumn+" = '"+s+"'  WHERE  rowid = "+IntToString(nRow)+" ";
                    }
                    else
                    {
                        SQL = "INSERT INTO cached2da_"+s2DA+" (rowid, "+sDBColumn+") VALUES ("+IntToString(nRow)+" , '"+s+"')";
                    }                       
                }
                else if(TestStringAgainstPattern("cls_feat_**", s2DA))
                {
                    //check that 2da row exisits
                    SQL = "SELECT rowid FROM cached2da_"+GetStringLeft(s2DA, 8)+" WHERE rowid="+IntToString(nRow);
                    PRC_SQLExecDirect(SQL);
                    //if the row exists, then update it
                    //otherwise insert a new row
                    if(PRC_SQLFetch() == PRC_SQL_SUCCESS
                        && PRC_SQLGetData(1) != "")
                    {
                        SQL = "UPDATE cached2da_cls_feat SET  "+sDBColumn+" = '"+s+"'  WHERE  rowid = "+IntToString(nRow)+" ";
                    }
                    else
                    {
                        SQL = "INSERT INTO cached2da_cls_feat (rowid, "+sDBColumn+") VALUES ("+IntToString(nRow)+" , '"+s+"')";
                    }                       
                }
                else
                {
                    SQL = "INSERT INTO cached2da VALUES ('"+s2DA+"' , '"+sDBColumn+"' , '"+IntToString(nRow)+"' , '"+s+"')";
                }   
                PRC_SQLExecDirect(SQL);
            }
        }
        //store it on the waypoint
        SetLocalString(oFileWP, "2DA_"+s2DA+"_"+sColumn+"_"+IntToString(nRow), s);
    }
    if (s=="****")
        return "";
    else
        return s;
}

The line that causes the problem is if(PRC_SQLFetch() == PRC_SQL_ERROR) which is commented out and replaced with if(FALSE) above. If I leave this line in, it crashes. If I remove it, it doesnt. However, this makes no sense to me Sad Also the crash doesnt happen on the first database it crashes on the second. So my logs look like:
nwserverlog1.txt
Code:

[Mon Mar 21 11:01:29]---- Server Options ----
Max Players: 6
Char Levels: (1-40)
Player Password: NO
DM Login Enabled: YES
Server Admin Login Enabled: YES
Post Game To Internet: NO
Game Type: Action
Difficulty: 3
PVP Setting: PARTY
Vault: SERVER
Only One Party: YES
Enforce Legal Characters: NO
Item Level Restrictions: NO
Player pausing: DISABLED
Auto Save: Enabled
Saving Characters in Saved Game
---- End Server Options ----
[Mon Mar 21 11:01:35] Loading Module: ConvoCCCache
.CREATE TABLE cached2da_feat ( rowid int(55),label varchar(255),feat varchar(255),description varchar(255),icon varchar(255),minattackbonus varchar(255),minstr varchar(255),mindex varchar(255),minint varchar(255),minwis varchar(255),mincon varchar(255),mincha varchar(255),minspelllvl varchar(255),prereqfeat1 varchar(255),prereqfeat2 varchar(255),gainmultiple varchar(255),effectsstack varchar(255),allclassescanuse varchar(255),category varchar(255),maxcr varchar(255),spellid varchar(255),successor varchar(255),crvalue varchar(255),usesperday varchar(255),masterfeat varchar(255),targetself varchar(255),orreqfeat0 varchar(255),orreqfeat1 varchar(255),orreqfeat2 varchar(255),orreqfeat3 varchar(255),orreqfeat4 varchar(255),reqskill varchar(255),reqskillminranks varchar(255),reqskill2 varchar(255),reqskillminranks2 varchar(255),constant varchar(255),toolscategories varchar(255),hostilefeat varchar(255),minlevel varchar(255),minlevelclass varchar(255),maxlevel varchar(255),minfortsave varchar(255),prereqepic varchar(255))
CREATE TABLE cached2da_portraits ( rowid int(255),baseresref varchar(255), sex varchar(255), race varchar(255), inanimatetype varchar(255), plot varchar(255), lowgore varchar(255) )
CREATE TABLE cached2da_appearance ( rowid int(55),label varchar(255), string_ref varchar(255), name varchar(255), race varchar(255), envmap  varchar(255), bloodcolor varchar(255), modeltype varchar(255), weaponscale varchar(255), wing_tail_scale varchar(255), helmet_scale_m varchar(255), helmet_scale_f varchar(255), moverate varchar(255), walkdist varchar(255), rundist varchar(255), perspace varchar(255), creperspace varchar(255), height varchar(255), hitdist varchar(255), prefatckdist varchar(255), targetheight varchar(255), abortonparry varchar(255), racialtype varchar(255), haslegs varchar(255), hasarms varchar(255), portrait varchar(255), sizecategory varchar(255), perceptiondist varchar(255), footsteptype varchar(255), soundapptype varchar(255), headtrack varchar(255), head_arc_h varchar(255), head_arc_v varchar(255), head_name varchar(255), body_bag varchar(255), targetable  varchar(255))
CREATE TABLE cached2da_spells ( rowid int(55),label varchar(255), name varchar(255), iconresref varchar(255), school varchar(255), range varchar(255), vs varchar(255), metamagic varchar(255), targettype varchar(255), impactscript varchar(255), bard varchar(255), cleric varchar(255), druid varchar(255), paladin varchar(255), ranger varchar(255), wizzsorc varchar(255), innate varchar(255), conjtime varchar(255), conjanim varchar(255), conjheadvisual varchar(255), conjhandvisual varchar(255), conjgrndvisual varchar(255), conjsoundvfx varchar(255), conjsoundmale varchar(255), conjsoundfemale varchar(255), castanim varchar(255), casttime varchar(255), castheadvisual varchar(255), casthandvisual varchar(255), castgrndvisual varchar(255), castsound varchar(255), proj varchar(255), projmodel varchar(255), projtype varchar(255), projspwnpoint varchar(255), projsound varchar(255), projorientation varchar(255), immunitytype varchar(255), itemimmunity varchar(255), subradspell1 varchar(255), subradspell2 varchar(255), subradspell3 varchar(255), subradspell4 varchar(255), subradspell5 varchar(255), category varchar(255), master varchar(255), usertype varchar(255), spelldesc varchar(255), useconcentration varchar(255), spontaneouslycast varchar(255), altmessage varchar(255), hostilesetting varchar(255), featid varchar(255), counter1 varchar(255), counter2 varchar(255), hasprojectile varchar(255))
CREATE TABLE cached2da_cls_feat ( rowid int(55),class varchar(255), FeatLabel varchar(255), FeatIndex varchar(255), List varchar(255), GrantedOnLevel varchar(255), OnMenu varchar(255))
CREATE TABLE cached2da ( file varchar(255), column varchar(255), rowid int(55), data varchar(255) )
SELECT label FROM cached2da_appearance WHERE ( rowid = 0 )
SELECT rowid FROM cached2da_appearance WHERE rowid=0
INSERT INTO cached2da_appearance (rowid, label) VALUES (0 , 'Dwarf')
SELECT string_ref FROM cached2da_appearance WHERE ( rowid = 0 )

nwnx_odbc.txt
Code:

NWNX ODBC2 plugin V.0.9.2.3
(c) 2005 by Ingmar Stieger (Papillon) and Jeroen Broekhuizen
visit us at http://www.nwnx.org

o Logfile maximum size limit is: 8388608 bytes
o Log level: Everything will be logged.
o Using SQLite connection.
o Hooking SCO....hooked at 5c4880
o Hooking RCO....hooked at 5c4760
o Connect successful.
o Got request: CREATE TABLE cached2da_feat ( rowid int(55),label varchar(255),feat varchar(255),description varchar(255),icon varchar(255),minattackbonus varchar(255),minstr varchar(255),mindex varchar(255),minint varchar(255),minwis varchar(255),mincon varchar(255),mincha varchar(255),minspelllvl varchar(255),prereqfeat1 varchar(255),prereqfeat2 varchar(255),gainmultiple varchar(255),effectsstack varchar(255),allclassescanuse varchar(255),category varchar(255),maxcr varchar(255),spellid varchar(255),successor varchar(255),crvalue varchar(255),usesperday varchar(255),masterfeat varchar(255),targetself varchar(255),orreqfeat0 varchar(255),orreqfeat1 varchar(255),orreqfeat2 varchar(255),orreqfeat3 varchar(255),orreqfeat4 varchar(255),reqskill varchar(255),reqskillminranks varchar(255),reqskill2 varchar(255),reqskillminranks2 varchar(255),constant varchar(255),toolscategories varchar(255),hostilefeat varchar(255),minlevel varchar(255),minlevelclass varchar(255),maxlevel varchar(255),minfortsave varchar(255),prereqepic varchar(255))
! SQL Error: SQL error: table cached2da_feat already exists
o Got request: CREATE TABLE cached2da_portraits ( rowid int(255),baseresref varchar(255), sex varchar(255), race varchar(255), inanimatetype varchar(255), plot varchar(255), lowgore varchar(255) )
o Got request: CREATE TABLE cached2da_appearance ( rowid int(55),label varchar(255), string_ref varchar(255), name varchar(255), race varchar(255), envmap  varchar(255), bloodcolor varchar(255), modeltype varchar(255), weaponscale varchar(255), wing_tail_scale varchar(255), helmet_scale_m varchar(255), helmet_scale_f varchar(255), moverate varchar(255), walkdist varchar(255), rundist varchar(255), perspace varchar(255), creperspace varchar(255), height varchar(255), hitdist varchar(255), prefatckdist varchar(255), targetheight varchar(255), abortonparry varchar(255), racialtype varchar(255), haslegs varchar(255), hasarms varchar(255), portrait varchar(255), sizecategory varchar(255), perceptiondist varchar(255), footsteptype varchar(255), soundapptype varchar(255), headtrack varchar(255), head_arc_h varchar(255), head_arc_v varchar(255), head_name varchar(255), body_bag varchar(255), targetable  varchar(255))
o Got request: CREATE TABLE cached2da_spells ( rowid int(55),label varchar(255), name varchar(255), iconresref varchar(255), school varchar(255), range varchar(255), vs varchar(255), metamagic varchar(255), targettype varchar(255), impactscript varchar(255), bard varchar(255), cleric varchar(255), druid varchar(255), paladin varchar(255), ranger varchar(255), wizzsorc varchar(255), innate varchar(255), conjtime varchar(255), conjanim varchar(255), conjheadvisual varchar(255), conjhandvisual varchar(255), conjgrndvisual varchar(255), conjsoundvfx varchar(255), conjsoundmale varchar(255), conjsoundfemale varchar(255), castanim varchar(255), casttime varchar(255), castheadvisual varchar(255), casthandvisual varchar(255), castgrndvisual varchar(255), castsound varchar(255), proj varchar(255), projmodel varchar(255), projtype varchar(255), projspwnpoint varchar(255), projsound varchar(255), projorientation varchar(255), immunitytype varchar(255), itemimmunity varchar(255), subradspell1 varchar(255), subradspell2 varchar(255), subradspell3 varchar(255), subradspell4 varchar(255), subradspell5 varchar(255), category varchar(255), master varchar(255), usertype varchar(255), spelldesc varchar(255), useconcentration varchar(255), spontaneouslycast varchar(255), altmessage varchar(255), hostilesetting varchar(255), featid varchar(255), counter1 varchar(255), counter2 varchar(255), hasprojectile varchar(255))
o Got request: CREATE TABLE cached2da_cls_feat ( rowid int(55),class varchar(255), FeatLabel varchar(255), FeatIndex varchar(255), List varchar(255), GrantedOnLevel varchar(255), OnMenu varchar(255))
o Got request: CREATE TABLE cached2da ( file varchar(255), column varchar(255), rowid int(55), data varchar(255) )
! SQL Error: SQL error: table cached2da already exists
o Got request: SELECT label FROM cached2da_appearance WHERE ( rowid = 0 )
o Sent response (0 bytes):
o Got request: SELECT rowid FROM cached2da_appearance WHERE rowid=0
o Sent response (0 bytes):
o Got request: INSERT INTO cached2da_appearance (rowid, label) VALUES (0 , 'Dwarf')
o Got request: SELECT string_ref FROM cached2da_appearance WHERE ( rowid = 0 )


Im using SQLite as my database BTW.
Back to top
View user's profile Send private message
Primogenitor



Joined: 08 Jan 2005
Posts: 88

PostPosted: Sat Mar 26, 2005 10:12    Post subject: Reply with quote

No replies? No-one is interested in a server crashing bug with SQLFetch()?
Back to top
View user's profile Send private message
Primogenitor



Joined: 08 Jan 2005
Posts: 88

PostPosted: Sat Mar 26, 2005 13:37    Post subject: Simplification = answer? Reply with quote

Ive stripped it down to the bare bones. Simply put this code in a blank module load event along with the aps includes then run the module using SQLite database. It will crash nwserver every time.

Code:

#include "aps_include"
void main()
{
    SQLInit();
    string SQL;
    SQL = "CREATE TABLE test (rowno int(55), cola varchar(55), colb varchar(55), colc varchar(55))";
    SQLExecDirect(SQL);

    SQL = "INSERT INTO test (rowno, cola) VALUES (1, 1)";
    SQLExecDirect(SQL);

    SQL = "SELECT colb FROM test WHERE (rowno = 1)";
    SQLExecDirect(SQL);
    if(SQLFetch())
        WriteTimestampedLogEntry(SQL+" worked");

}


After thinking about this more, it appears to be something to do with null database entries. If it would return a null value, SQLFetch crashes NWServer. This is different from if there was no database table, or row, or other error.
Back to top
View user's profile Send private message
Primogenitor



Joined: 08 Jan 2005
Posts: 88

PostPosted: Sat Mar 26, 2005 13:42    Post subject: Reply with quote

Here is a temporary fix for the problem. You have to specify a default value for all the columns when the table is defined. So the small script above becomes:
Code:

#include "aps_include"
void main()
{
    SQLInit();
    string SQL;
    SQL = "CREATE TABLE test (rowno int(55), "
        +"cola varchar(55) DEFAULT '_', "
        +"colb varchar(55) DEFAULT '_', "
        +"colc varchar(55) DEFAULT '_')";
    SQLExecDirect(SQL);

    SQL = "INSERT INTO test (rowno, cola) VALUES (1, 1)";
    SQLExecDirect(SQL);

    SQL = "SELECT colb FROM test WHERE (rowno = 1)";
    SQLExecDirect(SQL);
    if(SQLFetch())
        WriteTimestampedLogEntry(SQL+" worked");

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



Joined: 02 Jan 2005
Posts: 158

PostPosted: Sat Mar 26, 2005 13:48    Post subject: Reply with quote

Don't check for errors that way myself...it's a lot to dig through.

Cool, you just fixed it yourself Wink Maybe comment more on what you want to do generally...I'd go hashset myself for the spell data if you use it extensively (no way to tell the school through script). I just grabbed the fields I wanted from spells.2da and slapped into a table though.
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Fri Apr 01, 2005 23:10    Post subject: Reply with quote

Thanks for the info, Primogenitor. I will check this out, and if I am able to reproduce the crash, fix it.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sun Apr 03, 2005 11:19    Post subject: Reply with quote

I can not reproduce the crash with V.0.9.2.4. This is what I get in my log:

Quote:
o Got request: CREATE TABLE test (rowno int(55), cola varchar(55), colb varchar(55), colc varchar(55))
o Got request: INSERT INTO test (rowno, cola) VALUES (1, 1)
o Got request: SELECT colb FROM test WHERE (rowno = 1)
o Sent response (0 bytes):

_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows 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