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 
 
Can't solve getpersistentobject problem - converting BioDB

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



Joined: 23 Apr 2005
Posts: 7

PostPosted: Sun Apr 24, 2005 0:10    Post subject: Can't solve getpersistentobject problem - converting BioDB Reply with quote

I've been trying to convert my Dynamic Logbook to work with NWNX. Right now it uses BioDB persistence. To take full advantage of NWNX the system would have to be redesigned, but I should be able to convert it to NWNX as is. It means the difference between this being available for NWNX now or much, much later. The trick is that the Logbook gets stored as an object with all the persistent info as localvariables on it. Now that NWNX supports objects it should be doable. Everything else seems to work ok, except for retrieving the object. As far as I can tell the blob infos are made in the table, but 99% of the time, I can't retrieve it. The 1% of the time it works is mind-boggling to me. The way to initialize the sql db is to use the DM option of Burning down the library (destroy database) in the Logbook system. If and only if, as DM you store one or more books, that first book will be retrievable, but only the first one. Creating the first book as a PC will not work.

Here is the NWN scripting thread. Please I'm at the end of my rope on this one. I just don't know enough about the internal workings of NWNX and haven't a clue what RCO/SCO is.
Back to top
View user's profile Send private message
caesarbear2



Joined: 23 Apr 2005
Posts: 7

PostPosted: Sun Apr 24, 2005 0:52    Post subject: Reply with quote

Here's is the relevent code:
log_include
Code:

#include "aps_include"

// Zaddix's Dynamic Log Book - Revised Edition
// by caesarbear
// * Token Constants
int nBookTitleToken         = 6660;
int nByToken                = 6661;
int nAuthorToken            = 6662;
int nPageToken              = 6663;
int nCurrentPageToken       = 6664;
int nOfToken                = 6665;
int nTotalPagesToken        = 6666;
int nEditedByToken          = 6667;
int nCurrentPageAuthorToken = 6668;
int nOnToken                = 6669;
int nCurrentPageDateToken   = 6670;
int nCurrentPageTextToken   = 6671;
int nColorOff               = 6672;
int nColorIvoryWhite        = 6673;
int nColorYellowHighlight   = 6674;
int nColorWineBrown         = 6675;
int nColorOlive             = 6676;
int nColorRusty             = 6677;
int nColorDullLavender      = 6678;
// tokens 6680 - 6689 correspond to library shelf books
string LIBRARY_DB           = "LOG_LIBRARY";
string LIBRARY_BLOB         = "LOG_LIBRARY_BLOB";
object oModule              = GetModule();
int iDBExpire               = 0;

void log_Reset(object oObject=OBJECT_SELF);
void log_UpdateTokens(object oObject=OBJECT_SELF);
string log_CurrentDate();
string log_TruncateString(string sString, int MaxLength);
void log_NewBooktitle(object oLogBook, string sTitle, string sAuthor);
void log_NewPage(object oLogBook, string sPageText, string sPageAuthor, int bNoLog);
void log_DeletePage(object oLogBook);
void log_TurnPage(object oLogBook, int nPageTurn);
void log_ReadWholeBook(object oLogBook);
void log_ReadAloud(object oLogBook);
int log_GetIndicies();
string log_CreateIndex(string sTitle, string sAuthor);
string log_GetCatalog();
string log_CreateShortIndex(string sIndex);
void log_AddIndexToCatalog(string sIndex);
void log_RemoveIndexFromCatalog(string sIndex);
void log_SetBlockStorage(int bValue);
int log_GetBlockStorage();
int log_StoreBook(string sShortIndex, object oLogBook);
object log_RetrieveBook(string sShortIndex, location lActivator, object oActivator);
void log_DeleteBook(string sShortIndex);
void log_BurnLibrary();

//::///////////////////////////////////////////////
//:: Function: log_reset
//:://////////////////////////////////////////////
/*
    This function will reset the Log Book locals.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
void log_Reset(object oObject=OBJECT_SELF)
{
  int nTotalPages = GetLocalInt(oObject, "nTotalPages");

  SetLocalString(oObject, "sBookTitle", "");
  SetLocalString(oObject, "sAuthor", "");
  SetLocalInt(oObject, "nTotalPages", 0);
  SetLocalInt(oObject, "nCurrentPage", 0);

  int nCurrentPage;
  for (nCurrentPage = 1; nCurrentPage <= nTotalPages; nCurrentPage++)
  {
    SetLocalInt(oObject, "nCurrentPageNoLog" + IntToString(nCurrentPage), 0);
    SetLocalString(oObject, "sCurrentPageAuthor" + IntToString(nCurrentPage), "");
    SetLocalString(oObject, "sCurrentPageDate" + IntToString(nCurrentPage), "");
    SetLocalString(oObject, "sCurrentPageText" + IntToString(nCurrentPage), "");
  }

  // Update the tokens with the locals
  log_UpdateTokens(oObject);
} // end function


//::///////////////////////////////////////////////
//:: Function: log_update_tokens
//:://////////////////////////////////////////////
/*
    This function will updates tokens with the
    Log Book locals.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
// modified by caesarbear
void log_UpdateTokens(object oObject=OBJECT_SELF)
{
  string sBookTitle = GetLocalString(oObject, "sBookTitle");
  string sAuthor = GetLocalString(oObject, "sAuthor");
  int nTotalPages = GetLocalInt(oObject, "nTotalPages");
  int nCurrentPage = GetLocalInt(oObject, "nCurrentPage");
  int bNoLog = GetLocalInt(oObject, "nCurrentPageNoLog" + IntToString(nCurrentPage));
  string sCurrentPageAuthor = GetLocalString(oObject, "sCurrentPageAuthor" + IntToString(nCurrentPage));
  string sCurrentPageDate = GetLocalString(oObject, "sCurrentPageDate" + IntToString(nCurrentPage));
  string sCurrentPageText = GetLocalString(oObject, "sCurrentPageText" + IntToString(nCurrentPage));

  if (sBookTitle == "")
  {
    SetCustomToken(nBookTitleToken, "");
    SetCustomToken(nByToken, "");
    SetCustomToken(nAuthorToken, "");
  }
  else
  {
    SetCustomToken(nBookTitleToken, sBookTitle + "\n");
    SetCustomToken(nByToken, "by ");
    SetCustomToken(nAuthorToken, sAuthor + "\n");
  }

  if ((nCurrentPage > 0) && (nCurrentPage <= nTotalPages))
  {
    SetCustomToken(nPageToken, "Page ");
    SetCustomToken(nCurrentPageToken, IntToString(nCurrentPage));
    SetCustomToken(nOfToken, " of ");
    SetCustomToken(nTotalPagesToken, IntToString(nTotalPages) + "\n");
    if (bNoLog)
    {
        SetCustomToken(nEditedByToken, "");
        SetCustomToken(nCurrentPageAuthorToken, "");
        SetCustomToken(nOnToken, "");
        SetCustomToken(nCurrentPageDateToken, "");
    }
    else
    {
        SetCustomToken(nEditedByToken, "Edited by: ");
        SetCustomToken(nCurrentPageAuthorToken, sCurrentPageAuthor + "\n");
        SetCustomToken(nOnToken, "on ");
        SetCustomToken(nCurrentPageDateToken, sCurrentPageDate + "\n");
    }
    SetCustomToken(nCurrentPageTextToken, sCurrentPageText);
  }
  else
  {
    SetCustomToken(nPageToken, "");
    SetCustomToken(nCurrentPageToken, "");
    SetCustomToken(nOfToken, "");
    SetCustomToken(nTotalPagesToken, "");
    SetCustomToken(nEditedByToken, "");
    SetCustomToken(nCurrentPageAuthorToken, "");
    SetCustomToken(nOnToken, "");
    SetCustomToken(nCurrentPageDateToken, "");
    SetCustomToken(nCurrentPageTextToken, "");
  }
  SetCustomToken(nColorOff, "</c>");
  SetCustomToken(nColorIvoryWhite, "<cðáÒ>");
  SetCustomToken(nColorYellowHighlight, "<cðá¥>");
  SetCustomToken(nColorWineBrown, "<cªdd>");
  SetCustomToken(nColorOlive, "<c´È–>");
  SetCustomToken(nColorRusty, "<cÈxd>");
  SetCustomToken(nColorDullLavender, "<c‘‘Ã>");
} // end function


//::///////////////////////////////////////////////
//:: Function: log_current_date
//:://////////////////////////////////////////////
// redone for accurate time - caesarbear 1/30/05

string log_CurrentDate()
{
    int second, minute, hour, temp;
    string displayMinute, meridian;
    int  MINUTES_TO_THE_HOUR = FloatToInt(HoursToSeconds(1)/60);
    second = GetTimeSecond();
    minute = GetTimeMinute();
    hour = GetTimeHour();
    temp = 60*minute + second;
    minute = temp / MINUTES_TO_THE_HOUR;
    if (minute < 10)
        displayMinute = "0" + IntToString(minute);
    else
        displayMinute = IntToString(minute);
    if (hour == 12)
        meridian = "pm";
    else if (hour == 0)
    {
        hour = 12;
        meridian = "am";
    }
    else if (hour > 12)
    {
        hour = hour - 12;
        meridian = "pm";
    }
    else if (hour < 12)
        meridian = "am";
    string sDate = IntToString(GetCalendarMonth()) + "/" + IntToString(GetCalendarDay()) + "/" + IntToString(GetCalendarYear()) + " " + IntToString(hour) + ":" + displayMinute+meridian;
    return sDate;
}


//::///////////////////////////////////////////////
//:: Function: log_truncate_string
//:://////////////////////////////////////////////
/*
    This function will truncate a string if
    it's length is greater then the length
    specified.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
string log_TruncateString(string sString, int MaxLength)
{
  if (GetStringLength(sString) > MaxLength)
  {
    sString = GetStringLeft(sString, MaxLength);
  }

  return sString;

} // end function


//::///////////////////////////////////////////////
//:: Function: log_new_booktitle
//:://////////////////////////////////////////////
/*
    This function will set the title, author,
    and updated date for the Log Book.  It will
    also update the creation date if it hasn't
    already been set.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
void log_NewBooktitle(object oLogBook, string sTitle, string sAuthor)
{
  sTitle = log_TruncateString(sTitle, 40);
  sAuthor = log_TruncateString(sAuthor, 40);

  SetLocalString(oLogBook, "sBookTitle", sTitle);
  SetLocalString(oLogBook, "sAuthor", sAuthor);

  // Update the tokens with the locals
  log_UpdateTokens(oLogBook);
} // end function


//::///////////////////////////////////////////////
//:: Function: log_new_page
//:://////////////////////////////////////////////
/*
    This function will add a new page to the
    Log Book.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
void log_NewPage(object oLogBook, string sPageText, string sPageAuthor, int iNoLog)
{
  sPageAuthor = log_TruncateString(sPageAuthor, 40);

  int nTotalPages = GetLocalInt(oLogBook, "nTotalPages") + 1;
  int nCurrentPage = GetLocalInt(oLogBook, "nCurrentPage") + 1;

  SetLocalInt(oLogBook, "nTotalPages", nTotalPages);
  SetLocalInt(oLogBook, "nCurrentPage", nCurrentPage);

  int iPage;
  int iTemp;
  string sTemp;
  for (iPage = nTotalPages; iPage > nCurrentPage; iPage--)
  {
     iTemp = GetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(iPage-1));
     SetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(iPage), iTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(iPage-1));
     SetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(iPage), sTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageDate" + IntToString(iPage-1));
     SetLocalString(oLogBook, "sCurrentPageDate" + IntToString(iPage), sTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageText" + IntToString(iPage-1));
     SetLocalString(oLogBook, "sCurrentPageText" + IntToString(iPage), sTemp);
  }

  SetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(nCurrentPage), iNoLog);
  SetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(nCurrentPage), sPageAuthor);
  SetLocalString(oLogBook, "sCurrentPageDate" + IntToString(nCurrentPage), log_CurrentDate());
  SetLocalString(oLogBook, "sCurrentPageText" + IntToString(nCurrentPage), sPageText);

  // Update the tokens with the locals
  log_UpdateTokens(oLogBook);
} // end function


//::///////////////////////////////////////////////
//:: Function: log_delete_page
//:://////////////////////////////////////////////
/*
    This function will delete the current page
    in the Log Book.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
void log_DeletePage(object oLogBook)
{
  int nTotalPages = GetLocalInt(oLogBook, "nTotalPages");
  int nCurrentPage = GetLocalInt(oLogBook, "nCurrentPage");

  int iPage;
  int iTemp;
  string sTemp;
  for (iPage = nCurrentPage; iPage < nTotalPages; iPage++)
  {
     iTemp = GetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(iPage+1));
     SetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(iPage), iTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(iPage+1));
     SetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(iPage), sTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageDate" + IntToString(iPage+1));
     SetLocalString(oLogBook, "sCurrentPageDate" + IntToString(iPage), sTemp);
     sTemp = GetLocalString(oLogBook, "sCurrentPageText" + IntToString(iPage+1));
     SetLocalString(oLogBook, "sCurrentPageText" + IntToString(iPage), sTemp);
  }

  SetLocalInt(oLogBook, "nCurrentPageNoLog" + IntToString(nCurrentPage), 0);
  SetLocalString(oLogBook, "sCurrentPageAuthor" + IntToString(nTotalPages), "");
  SetLocalString(oLogBook, "sCurrentPageDate" + IntToString(nTotalPages), "");
  SetLocalString(oLogBook, "sCurrentPageText" + IntToString(nTotalPages), "");

  SetLocalInt(oLogBook, "nTotalPages", nTotalPages-1);

  if (nCurrentPage > nTotalPages-1)
  {
    SetLocalInt(oLogBook, "nCurrentPage", nCurrentPage-1);
  }

  // Update the tokens with the locals
  log_UpdateTokens(oLogBook);
}


//::///////////////////////////////////////////////
//:: Function: log_turnpage
//:://////////////////////////////////////////////
/*
    This function will turn the page of the
    Log Book by nPageTurn.
*/
//:://////////////////////////////////////////////
//:: Created By:  Zaddix
//:: Created On: July 13, 2002
//:://////////////////////////////////////////////
void log_TurnPage(object oLogBook, int nPageTurn)
{
  int nCurrentPage = GetLocalInt(oLogBook, "nCurrentPage") + nPageTurn;
  SetLocalInt(oLogBook, "nCurrentPage", nCurrentPage);

  // Update the tokens with the locals
  log_UpdateTokens(oLogBook);
}

//
// Function: log_readwholebook
/*
    This will send the entire contents of the book as a message to the PC
*/
// created by ceasarbear 1/29/05
void log_ReadWholeBook(object oLogBook)
{
    string sBookTitle = GetLocalString(oLogBook, "sBookTitle");
    string sAuthor = GetLocalString(oLogBook, "sAuthor");
    int nTotalPages = GetLocalInt(oLogBook, "nTotalPages");
    int iPage;
    object oActivator = GetLocalObject(OBJECT_SELF, "oActivator");
    SendMessageToPC(oActivator, "<cÈxd>"+sBookTitle+"</c>");
    SendMessageToPC(oActivator, "<cÈxd>by "+sAuthor+"</c>");
    for (iPage = 0; iPage <= nTotalPages; iPage++)
    {
        SendMessageToPC(oActivator, "<cðáÒ>"+GetLocalString(oLogBook, "sCurrentPageText" + IntToString(iPage))+"</c>");
    }
}

//
// Function: log_readaloud
/*
    This will cause the Activator to speak the current page
*/
// created by ceasarbear 1/29/05
void log_ReadAloud(object oLogBook)
{
    int nCurrentPage = GetLocalInt(oLogBook, "nCurrentPage");
    string sCurrentPageText = GetLocalString(oLogBook, "sCurrentPageText" + IntToString(nCurrentPage));
    sCurrentPageText = "<cðáÒ>" + sCurrentPageText + "</c>";
    object oActivator = GetLocalObject(OBJECT_SELF, "oActivator");
    AssignCommand(oActivator, ActionSpeakString(sCurrentPageText));
}

//
// Funstion: log_CleanString
string log_CleanString(string sString)
{
    string sTemp = "";
    int iPos = FindSubString(sString, "%");
    while (iPos != -1)
    {
        sTemp = GetStringLeft(sString, iPos);
        sTemp += GetStringRight(sString, iPos+1);
        sString = sTemp;
        iPos = FindSubString(sString, "%");
    }
    iPos = FindSubString(sString, "{");
    while (iPos != -1)
    {
        sTemp = GetStringLeft(sString, iPos);
        sTemp += GetStringRight(sString, iPos+1);
        sString = sTemp;
        iPos = FindSubString(sString, "{");
    }
    return sString;
}



// Function: log_GetIndicies
int log_GetIndicies()
{
    int iIndicies = GetPersistentInt(oModule, "Indices", LIBRARY_DB);
    return iIndicies;
}

//
// Function: log_create_index
// created by ceasarbear
string log_CreateIndex(string sTitle, string sAuthor)
{
    // using "{" for index separator, "%" for title/author divider
    string sBookTitle = log_CleanString(sTitle);
    string sBookAuthor = log_CleanString(sAuthor);
    string sCatalogIndex = sBookTitle +"%"+ sBookAuthor;
    return sCatalogIndex;
}

//
//
string log_GetCatalog()
{
    string sCatalog = GetPersistentString(oModule, "Catalog", LIBRARY_DB);
    return sCatalog;
}

//
//
string log_CreateShortIndex(string sIndex)
{
    string sTemp = "";
    string sTemp2 = "";
    int iLength, x;
    iLength = GetStringLength(sIndex);
    for (x=0; x<iLength; x++)
    {
        if(GetSubString(sIndex, x, 1) != " ")
            sTemp += GetSubString(sIndex, x, 1);
    }

    if (GetStringLength(sTemp) < 33)
        return sTemp;
    else
        sTemp2 = GetStringLeft(sTemp, 20);
        sTemp2 += GetStringRight(sTemp, 12);
    return sTemp2;
}

//
//
void log_AddIndexToCatalog(string sIndex)
{
    string sCatalog = GetPersistentString(oModule, "Catalog", LIBRARY_DB);
    sCatalog = sCatalog + sIndex + "{";
    SetPersistentString(oModule, "Catalog", sCatalog, iDBExpire, LIBRARY_DB);
    int iIndicies = GetPersistentInt(oModule, "Indices", LIBRARY_DB);
    SetPersistentInt(oModule, "Indices", ++iIndicies, iDBExpire, LIBRARY_DB);
}

void log_RemoveIndexFromCatalog(string sIndex)
{
    string sCatalog = GetPersistentString(oModule, "Catalog", LIBRARY_DB);
    int iIndexStart = FindSubString(sCatalog, sIndex);
    string sTemp = GetStringLeft(sCatalog, iIndexStart);
    int iIndexLength = GetStringLength(sIndex);
    int iIndexEnd = iIndexStart + iIndexLength;
    int iCatalogLength = GetStringLength(sCatalog);
    sTemp += GetStringRight(sCatalog, (iCatalogLength - iIndexEnd) - 1);
    SetPersistentString(oModule, "Catalog", sTemp, iDBExpire, LIBRARY_DB);
    int iIndicies = GetPersistentInt(oModule, "Indices", LIBRARY_DB);
    SetPersistentInt(oModule, "Indices", --iIndicies, iDBExpire, LIBRARY_DB);
}

//
//
void log_SetBlockStorage(int bValue)
{
    SetPersistentInt(oModule, "BlockStorage", bValue, iDBExpire, LIBRARY_DB);
}

//
//
int log_GetBlockStorage()
{
    int bValue = GetPersistentInt(oModule, "BlockStorage", LIBRARY_DB);
    return bValue;
}

//
//
int log_StoreBook(string sShortIndex, object oLogBook)
{
    SetPersistentObject(oModule, sShortIndex, oLogBook, iDBExpire, LIBRARY_BLOB);
    return TRUE; //no check in nwnx
}

//
//
object log_RetrieveBook(string sShortIndex, location lActivator, object oActivator)
{
    sShortIndex = SQLEncodeSpecialChars(sShortIndex);
    string sTag = GetTag(oModule);
    SetLocalString(oModule, "NWNX!ODBC!SETSCORCOSQL", "SELECT val FROM "+LIBRARY_BLOB+" WHERE player='~' AND tag='"+sTag+"' AND name='"+sShortIndex+"'");
    object oNewLogbook = RetrieveCampaignObject ("NWNX", "-", lActivator, oActivator);
    return oNewLogbook;
}

//
//
void log_DeleteBook(string sShortIndex)
{
    DeletePersistentVariable(oModule, sShortIndex, LIBRARY_BLOB);
}

//
//
void log_BurnLibrary()
{
    SQLExecDirect("DROP TABLE " + LIBRARY_BLOB);
    SQLExecDirect("DROP TABLE " + LIBRARY_DB);
    SendMessageToAllDMs("Creating Table " + LIBRARY_BLOB + " for SQLite...");
    SQLExecDirect("CREATE TABLE " + LIBRARY_BLOB + " (" +
        "player varchar(64) NOT NULL default '~'," +
        "tag varchar(64) NOT NULL default '~'," +
        "name varchar(64) NOT NULL default '~'," +
        "val blob," +
        "expire int(11) default NULL," +
        "last timestamp NOT NULL default current_timestamp," +
        "PRIMARY KEY (player,tag,name)" +
        ")");
    SendMessageToAllDMs("Creating Table " + LIBRARY_DB + " for SQLite...");
    SQLExecDirect("CREATE TABLE " + LIBRARY_DB + " (" +
        "player varchar(64) NOT NULL default '~'," +
        "tag varchar(64) NOT NULL default '~'," +
        "name varchar(64) NOT NULL default '~'," +
        "val text," +
        "expire int(11) default NULL," +
        "last timestamp NOT NULL default current_timestamp," +
        "PRIMARY KEY (player,tag,name)" +
        ")");
}

log_libretrieve
Code:

#include "log_include"

void main()
{
    object oActivator = GetLocalObject(OBJECT_SELF, "oActivator");
    location lActivator = GetLocation(oActivator);
    object oLogBook = GetLocalObject(OBJECT_SELF, "oLogBook");
    int iBookNumber = GetLocalInt(OBJECT_SELF, "ShelfBookNumber");
    string sTitle = GetLocalString(OBJECT_SELF, "LibraryTitle"+IntToString(iBookNumber));
    string sAuthor = GetLocalString(OBJECT_SELF, "LibraryAuthor"+IntToString(iBookNumber));

    string sIndex = log_CreateIndex(sTitle, sAuthor);
    string sShortIndex = log_CreateShortIndex(sIndex);

    SetLocalInt(oActivator, "AutoActivate", TRUE);

    object oNewBook = log_RetrieveBook(sShortIndex, lActivator, oActivator);
    DestroyObject(oLogBook);

}


And a link to the test mod I'm using and the sqlite.db[/code]
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Mon Apr 25, 2005 8:16    Post subject: Reply with quote

You will probably get more and faster help if you track the problem down a bit more (i.e. reduce the code a bit). Also, please ALWAYS post the nwnx_odbc.txt log file, or nobody will be able to tell you what is going on.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
caesarbear2



Joined: 23 Apr 2005
Posts: 7

PostPosted: Tue Apr 26, 2005 5:38    Post subject: Reply with quote

Sorry for putting too much up there, I should have trimmed it.
This is the problem part. I can't use the default GetPersistentObject because it assumes it belongs to the calling PC. Either way, the retrieval behaves oddly and will only work under very specific conditions (first DM created book.)
Code:
object log_RetrieveBook(string sShortIndex, location lActivator, object oActivator)
{
    sShortIndex = SQLEncodeSpecialChars(sShortIndex);
    string sTag = GetTag(oModule);
    SetLocalString(oModule, "NWNX!ODBC!SETSCORCOSQL", "SELECT val FROM "+LIBRARY_BLOB+" WHERE player='~' AND tag='"+sTag+"' AND name='"+sShortIndex+"'");
    object oNewLogbook = RetrieveCampaignObject ("NWNX", "-", lActivator, oActivator);
    return oNewLogbook;
}


I didn't realize there was a log file for the odbc2, that might help me figure some of this out. Here are the beginning and end of the logfile:

Quote:

o Logfile maximum size limit is: 524288 bytes
o Log level: Everything will be logged.
o Using SQLite connection.
o Hooking SCO....hooked at 5c4320
o Hooking RCO....hooked at 5c4200
o Connect successful.
...
o Got request: SELECT val FROM LOG_LIBRARY WHERE player='~' AND tag='DEMOLogbookRevised' AND name='Indices'
o Sent response (1 bytes): 2
o Got request (scorco): SELECT val FROM LOG_LIBRARY_BLOB WHERE player='~' AND tag='DEMOLogbookRevised' AND name='Whynotus?~VinoSwift'
o Disconnecting from database.

the book is called Whynotus? and is created by the PC Vino Swift. My system creates an index string for the book: "Whynotus?%VinoSwift" I see that the % character is changed to a ~ character. Is a % an illegal character to use? I need a character that would not be use in normal prose, any suggestions? Also there is no logged Sent response after a scorco request, is this normal?
Back to top
View user's profile Send private message
caesarbear2



Joined: 23 Apr 2005
Posts: 7

PostPosted: Tue Apr 26, 2005 6:14    Post subject: Reply with quote

ARRGH! How aggravating! That was the problem, the "%" character. I replaced it with a "@" and things seem to be working fine now. Can someone please tell me the "@" will cause me trouble or not?
Back to top
View user's profile Send private message
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Tue Apr 26, 2005 11:08    Post subject: Reply with quote

% is a wildcard in MySQL, not familiar with SQLite.
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
caesarbear2



Joined: 23 Apr 2005
Posts: 7

PostPosted: Wed Apr 27, 2005 20:19    Post subject: Reply with quote

I was using SQLite. The SQL flavors should all be the same when it comes to characters. That would be extremely confusing if they weren't. I have % _ * as wildcards, ' + -- should be avoided too. Any others?
Back to top
View user's profile Send private message
Acrodania



Joined: 02 Jan 2005
Posts: 208

PostPosted: Wed Apr 27, 2005 20:59    Post subject: Reply with quote

Apostrophes are bad too.

They are field seperators and the equiv of quotes in the SQL language.....
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Fri Apr 29, 2005 19:11    Post subject: Reply with quote

I do not want to confuse anbody, but the % sign did not show up in the log file because ODBC2 converts any % characters before it outputs to the log (which has nothing to do with SQL).

You got it right though, % acts as a wildcard and should not be used in SQL tables.

Just a little background info Smile
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
caesarbear2



Joined: 23 Apr 2005
Posts: 7

PostPosted: Sun May 01, 2005 5:45    Post subject: Reply with quote

Quote:
Apostrophes are bad too.

Yeah, that's the one I knew, (and actually listed above but the formatting hid it.) I noticed that ' is handled by SQLEncodeSpecialChars, but none of the other SQL special characters are. Shouldn't they all be checked? If not encoded, then simply blocked?
Back to top
View user's profile Send private message
entropy



Joined: 23 Jun 2009
Posts: 6

PostPosted: Tue Jul 21, 2009 16:57    Post subject: Reply with quote

Ahem - and I face the opposite problem - I wish to run a limited search, by excluding one type of leading character - or by running a search on merely a limited number of characters - to allow a seperate search through a database with the help of ZDlg...

Quote:
o Got request: SELECT DISTINCT shelf FROM Storage WHERE shelf LIKE '[^:]~' ORDER BY shelf ASC


But what I wanted was WHERE shelf LIKE '[^:]%'

I have no idea how to prevent that particular change with the scripts...

Is there a way I can get a wildcard through to my executed SQL statement or not?
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Tue Jul 21, 2009 19:00    Post subject: Reply with quote

SQLExecDirect() bypasses SQLEncodeSpecialChars().
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
entropy



Joined: 23 Jun 2009
Posts: 6

PostPosted: Tue Jul 21, 2009 19:31    Post subject: Reply with quote

It does... yes, it does - but on the way to the SQL functions, someone messes with the SQL request.

I mean it is sensible to filter certain characters out ... but I wasn't even able to identify who does it, it seems not to be in the NWNXODBC library.

I'm using it with Sqlite... and I use
Code:

void FetchDBGroups(string sSQLLike = "[^:]%", int bOrderByDate=FALSE)
{
    string sSQLStmt = "SELECT DISTINCT shelf FROM " + TABLE_NAME;
    if(sSQLLike != "")
        sSQLStmt += " WHERE shelf LIKE '" + sSQLLike + "'";

    if(bOrderByDate) sSQLStmt += " ORDER BY lastmodified ASC";
    else sSQLStmt += " ORDER BY shelf ASC";

    SQLExecDirect(sSQLStmt);
}


So, yeah, I hoped SQLExecDirect would bypass that encoding, but the EncodeSQLSpecial Char seems only to take care of '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