Your concern is valid. You should not be writing MemHandles to the database.
DmWrite just writes the bits at the address it is given, it does no dereferencing of passed MemHandles. You should be passing the actual data to DmWrite, not a handle. See http://www.palmos.com/dev/support/docs/recipes/recipe_basic_db_operations.html for additional info. Hope that helps... Dave "meg" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I'm concerned about some of my code - I don't know how to figure out if it > is working correctly. I have a structure that includes a mem handle and I'm > not sure how exactly DMWrite works and whether it copies the data from the > mem handle or whether I should be grabbing the data out of the handle before > calling DmWrite.... > > Would someone please let me know 1) if this code should assumedly work and > 2) how I might be able to browse a database and see if it actually is > storing what i think it is? > thanks > ******************************code**************************** > > typedef struct { > > MemHandle QuestionAnswers; > UInt8 sessionFinished; > > } packed_question_type; > > /*-------------------------------------------------------------------------- > ----------------------------------------------------------- > Function: SaveAnswersToDatabase > Desccription: saves answers from current session to database > Parameters: index for current session's record > Return: error code if necessary, otherwise 0 > -------------------------------------------------------------------------- -- > ---------------------------------------------------------*/ > Err SaveAnswersToDatabase(UInt16 index) { > > MemHandle h; > MemPtr p; > Err error; > > //allocate memory for the packed question's string > packedQuestion.QuestionAnswers = MemHandleNew(1); > > //store whether the session was completed > packedQuestion.sessionFinished=theQuestion.sessionFinished; > > //pack question for storage > PackQuestion(theQuestion); > > //open questions database > error=OpenQuestionsDatabase(); > > //grab a handle to a new record > h = DmNewRecord(questionDatabaseRef, &index, sizeof(packedQuestion)); > > //if handle was aquired sucesfully > if (h) { > > //lock handle and grab pointer > p = MemHandleLock(h); > > error = DmWrite(p, 0, &packedQuestion, sizeof(packedQuestion)); > > //unlock the handle > MemPtrUnlock(p); > > //release record and set dirty bit > DmReleaseRecord(questionDatabaseRef,index,true); > > }//if (h) > > //close questions database > error = CloseQuestionsDatabase(); > > //free memory used by packed question > MemHandleFree(packedQuestion.QuestionAnswers); > > return error; > > }//SaveAnswersToDatabase > > > > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
