I am not sure if \0 after Test message will be stored in DB (as u use
StrLen()). So when do StrPrintF in read, it doesn't know where to stop.

Jacky

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Young
S. Cho
Sent: Friday, February 02, 2001 9:48 AM
To: Palm Developer Forum
Subject: Garbage characters appended when text inserted/read from DB


Hi all,

I'm writing simple Palm DB code to write text strings to the database and
then to read it back. However, when I read the values back, I'm getting
garbage characters appended to my text string. Now, I'm not sure whether the
garbage is getting added at the insert or read, but has anyone seen
something similar to this?

Thanks for any advice or suggestions...

Young Cho

[EMAIL PROTECTED]

The code fragment looks something like this:

------- Code to write & read from the DB

// Open the database - my routine to create the DB and to open it

error = OpenDB(appDatabaseName, 'DATA', appCreatorID);

iIndex = WriteDB("Test message1\0", 0);

iIndex = WriteDB("Test message2\0", 1);

for(iIndex = 0;iIndex < GetNumRecords();iIndex++)

{

    record = ReadDB(iIndex);

    StrPrintF(msg, "%2d:[%s]\n", iIndex, record);

    DisplayMessage(msg);

}

error = CloseDB();



----- WriteDB looks like this ------

UInt16 WriteDB(char *pText, UInt16 iRecPos)

{

char *pTmpPtr;

Err error;

MemHandle newRecordH;

newRecordH = DmNewRecord(gLibDB, &iRecPos, StrLen(pText));

pTmpPtr = MemHandleLock(newRecordH);

error = DmWrite(pTmpPtr, 0, pText, StrLen(pText));

MemHandleUnlock(newRecordH);

// Unset the record's busy bit

DmReleaseRecord(gLibDB, iRecPos, true);

return(iRecPos);

}



----- ReadDB looks like this -----

char * ReadDB(UInt16 iRecPos)

{

Char *pText = NULL;

MemHandle recordH;

static char datatext[1024];

MemSet(&datatext, sizeof(datatext), 0);

recordH = DmQueryRecord(gLibDB, iRecPos);

pText = MemHandleLock(recordH);

StrPrintF(datatext, "%s\0", pText);

MemHandleUnlock(recordH);

return(datatext);

}




--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to