I want to create the data base of my application in which i want to store some 
variable values when the application exit.when their is no data base it create 
it and store the default value  4 the variable.
and if database allready  their in that case read the valus 4 that.
the problem with me is that i m unable to write the record in the data base 
.the code doest give any error but record is not inserted their in database so 
4 second the applicaion run it show the null hundle bcz their is no record in 
database .
here is my code
typedef struct {
 UInt32 CreatorID,CreatorID1,CreatorID2,CreatorID3,CreatorID4;
   
} ToDayDBRecord;

typedef ToDayDBRecord                   ToDayDBRecordType;
typedef ToDayDBRecord*                  ToDayDBRecordPtr;
static Err ToDayGetDatabase()
{
        Err error = 0;
        DmOpenRef dbP;  
        LocalID dbID;
    UInt16 size;
    MemHandle newRecordH;
    ToDayDBRecordType  recordWr;
        ToDayDBRecordPtr TodayAppCreatoridP; 

     UInt16 index = dmMaxRecordIndex;  
   
    recordWr.CreatorID=SysFileCAddressMe;
  
        dbP = DmOpenDatabaseByTypeCreator (toDayType , 
appFileCreator,dmModeReadWrite);
        
        if (!dbP)
                {               
                error = DmCreateDatabase 
(0,toDayDBName,appFileCreator,toDayType, false);               
                
                        if (error)
                    { 
                    FrmAlert(RecordAlert);      
                        FrmAlert(ToDoListEmptyAlert);
                        return error;
                     }                       
           dbP = DmOpenDatabaseByTypeCreator (toDayType ,appFileCreator, 
dmModeReadWrite);        
                if (!dbP)
                {
                   FrmAlert(ToDoListEmptyAlert);
                   FrmAlert(RecordAlert); 
                   return (1);
                }        
         dbP=NULL;      
         dbID = DmFindDatabase (0, toDoDBName);         
                        if (dbID)
                         {                        
                           dbP = DmOpenDatabase(0, dbID, dmModeReadWrite);      
                  
                                if (dbP)
                                {                                       
                                        index=DmNumRecords (dbP);
                                        size= sizeof(recordWr.CreatorID)+1;     
                                                
                         newRecordH= DmNewHandle(dbP,size);
                    
                                        if (newRecordH== NULL)
                                        { 
                                                FrmAlert(RecordAlert);
                                                return dmErrMemError;           
                      
                                        }
                                             
                                                        TodayAppCreatoridP = 
(ToDayDBRecordPtr)MemHandleLock (newRecordH);
                                                 
                                                        
DmWrite(TodayAppCreatoridP,0,&recordWr.CreatorID,size);
                                                        
                                                        MemPtrUnlock 
(TodayAppCreatoridP);
                                                 
                                                        error = 
DmAttachRecord(dbP,&index,newRecordH, 0);
                                                         FrmAlert(RecordAlert); 
                                                        if (error) 
                                                        {
                                                                 
FrmAlert(RecordAlert); 
                                                                
MemHandleFree(newRecordH); 
                                                                return (1);     
                                                        }               
                                                  
                                }                                               
         
                            }  
                        }                       

                else    {               
                                                index=DmNumRecords (dbP);       
                
                                        newRecordH = (MemHandle)DmQueryRecord 
(dbP,index);
                                TodayAppCreatoridP = (ToDayDBRecordPtr) 
MemHandleLock (newRecordH);     
                                CreatorId=TodayAppCreatoridP->CreatorID;
                                    MemHandleUnlock (newRecordH);       
                                     DmCloseDatabase(dbP);                      
                                }       
         ToDaysDB = dbP;
         DmCloseDatabase(dbP);  
        return 0;
}
the problem is to write the new record  i also try the DmNewRecord is also has 
the same problem.
 i m trying the write the value of just 1 varialbe for test after that all 
variable can be write.
where is the proble i dont understand.
so thanks if any 1 solve my problem.
-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to