×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    May 2010
    Posts
    152

    Problem in Opening Table

    [Platform : Symbian C++, S60, 3rd Edition, FP1]

    Hi,

    I have created a database and a table in it to store SMS details, its showing that the database and table is being created successfully but at the time of opening the table it return KErrNotFound.

    Following are the lines of code :

    Code:
    //Function used to create database
    TInt CDatabaseHandler::CreateDatabaseL()       
    {
        //TInt errno;
    	User::InfoPrint(_L("Start..."));
    	User::After(2000000);
    	
    	Close();
    	
    	if(BaflUtils::FileExists(iFsSession,KDbName))
    	{
    		if(iOpen)
    			Close();
    		CEikonEnv::Static()->FsSession().Delete(KDbName);
    		
    		iOpen = EFalse;
    	}
    	
    	TRAPD(errno,
    		iFileStore = CPermanentFileStore::CreateL(iFsSession, KDbName,
    				EFileRead|EFileWrite);
    		iFileStore->SetTypeL(iFileStore->Layout());// Set file store type
        	TStreamId id = iMobileNannyDb.CreateL(iFileStore);// Create stream object
        	iFileStore->SetRootL(id);// Keep database id as root of store
        	iFileStore->CommitL();// Complete creation by commiting
        	);
    	
        	if(errno!=KErrNone)
        	{
        	return errno;
        	}
    
     	iOpen = ETrue;
    
     	User::InfoPrint(_L("Database Created"));
        User::After(2000000); 	
     	
        CreateSMSTableL();                                     
        
     	User::InfoPrint(_L("Table Created"));
        User::After(2000000); 	
    
    //    CreateSMSIndexL();
    //    User::InfoPrint(_L("Index Created"));
    //    User::After(2000000); 	
    
        return KErrNone;
    }
    and this is my table creation code
    Code:
    AddSMStWithCppApiL(const TDesC& aPhoneNumber,
    						const TDesC& aSMSText,
    						const TDesC& aDirection,
    						const TDateTime aDateTime
    						)
    {
    	 RDbTable SMStable;
    	 //RDbColWriteStream writeStream;
    	 TInt err = SMStable.Open(iMobileNannyDb, KSMSTableName, SMStable.EUpdatable);
    	 
    	 if(err!=KErrNone)
    	 {
    		 User::InfoPrint(_L("error in opening"));   //here  is the problem
    	 	return err;
    	 }
    	 
    	 CDbColSet* SMSColSet = SMStable.ColSetL();
    	 CleanupStack::PushL(SMSColSet);
    	 
    	 SMStable.Reset();
    	 
    	 TRAPD(error,
    			 SMStable.InsertL();
    	 SMStable.SetColL(SMSColSet->ColNo(KColPhoneNumber), aPhoneNumber);   
    	 SMStable.SetColL(SMSColSet->ColNo(KColDirection), aDirection);   
    	 SMStable.SetColL(SMSColSet->ColNo(KColDateTime), aDateTime);
    	 SMStable.SetColL(SMSColSet->ColNo(KColSMSText), aSMSText);	 	    
        		//writeStream.OpenL(table, SMSColSet->ColNo(KColSMSText));
        		//writeStream.WriteL(aSMSText);
    	 	);
    
    
    	 
    	 if(error!=KErrNone)
    	    {
    	 	return error;
    	    }
    		
    	 //writeStream.Close();
    
    	 TRAP(err, SMStable.PutL());  
    		if(err!=KErrNone)
    	 {
    	 	return err;
    	 }   
    		
    		 User::InfoPrint(_L("Record Inserted"));
    		 User::After(2000000);
    	 
    	 CleanupStack::PopAndDestroy(SMSColSet);
    	 SMStable.Close();
    		
    	 return KErrNone;
    }
    Can anyone please tell me what is the problem ??

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Problem in Opening Table

    You have not shown CreateSMSTableL, so it is hard to tell what happens exactly.

  3. #3
    Regular Contributor
    Join Date
    May 2010
    Posts
    152

    Re: Problem in Opening Table

    [Platform : Symbian C++, S60, 3rd Edition, FP1]

    Hi Wizard_hu,
    Here is the updated code with the CreateSMSTableL function.... plz look at it and tell me what is the problem

    Following are the lines of code :

    Code:
    //Function used to create database
    TInt CDatabaseHandler::CreateDatabaseL()       
    {
        //TInt errno;
    	User::InfoPrint(_L("Start..."));
    	User::After(2000000);
    	
    	Close();
    	
    	if(BaflUtils::FileExists(iFsSession,KDbName))
    	{
    		if(iOpen)
    			Close();
    		CEikonEnv::Static()->FsSession().Delete(KDbName);
    		
    		iOpen = EFalse;
    	}
    	
    	TRAPD(errno,
    		iFileStore = CPermanentFileStore::CreateL(iFsSession, KDbName,
    				EFileRead|EFileWrite);
    		iFileStore->SetTypeL(iFileStore->Layout());// Set file store type
        	TStreamId id = iMobileNannyDb.CreateL(iFileStore);// Create stream object
        	iFileStore->SetRootL(id);// Keep database id as root of store
        	iFileStore->CommitL();// Complete creation by commiting
        	);
    	
        	if(errno!=KErrNone)
        	{
        	return errno;
        	}
    
     	iOpen = ETrue;
    
     	User::InfoPrint(_L("Database Created"));
        User::After(2000000); 	
     	
        CreateSMSTableL();                                     
        
     	User::InfoPrint(_L("Table Created"));
        User::After(2000000); 	
    
    //    CreateSMSIndexL();
    //    User::InfoPrint(_L("Index Created"));
    //    User::After(2000000); 	
    
        return KErrNone;
    }
    //and this is my table creation code
    Code:
    void CDatabaseHandler::CreateSMSTableL()
    {
    	    TDbCol phoneNumberCol(KColPhoneNumber, EDbColText, KMaxPhoneNumberLength); //EDbColText);   
    	    TDbCol SMSTextCol(KColSMSText, EDbColText, KMaxSMSLength); //Using default length
    	    TDbCol dateTimeCol(KColDateTime, EDbColDateTime, KMaxDateTimeLength); //Using default length
    	    TDbCol directionCol(KColDirection, EDbColText, KMaxDirectionLength); //Using default length    
    	    
    	    // Add the columns to column set
    	    CDbColSet* SMSColSet = CDbColSet::NewLC();
    	    SMSColSet->AddL(phoneNumberCol);
    	    SMSColSet->AddL(SMSTextCol);
    	    SMSColSet->AddL(dateTimeCol);
    	    SMSColSet->AddL(directionCol);
    	    
    	    TInt errno;
    	    
    	    TRAP(errno, iMobileNannyDb.CreateTable(KSMSTableName,*SMSColSet));
    	    
    	    if(errno != KErrNone)
    	    	{
    	    	User::InfoPrint(_L("Table Open Error"));
    	    	User::After(3000000);
    	    	}
    	    
    	    CleanupStack::PopAndDestroy(SMSColSet);
    	    
    	    User::InfoPrint(_L("Table Created"));        
    	    User::After(2000000);
    }
    Code:
    //This is the function to store details in table
    void CDatabaseHandler::AddSMStWithCppApiL(const TDesC& aPhoneNumber,
    						const TDesC& aSMSText,
    						const TDesC& aDirection,
    						const TDateTime aDateTime
    						)
    {
    	 RDbTable SMStable;
    	 //RDbColWriteStream writeStream;
    	 TInt err = SMStable.Open(iMobileNannyDb, KSMSTableName, SMStable.EUpdatable);
    	 
    	 if(err!=KErrNone)
    	 {
    		 User::InfoPrint(_L("error in opening"));   //here  is the problem
    	 	return err;
    	 }
    	 
    	 CDbColSet* SMSColSet = SMStable.ColSetL();
    	 CleanupStack::PushL(SMSColSet);
    	 
    	 SMStable.Reset();
    	 
    	 TRAPD(error,
    			 SMStable.InsertL();
    	 SMStable.SetColL(SMSColSet->ColNo(KColPhoneNumber), aPhoneNumber);   
    	 SMStable.SetColL(SMSColSet->ColNo(KColDirection), aDirection);   
    	 SMStable.SetColL(SMSColSet->ColNo(KColDateTime), aDateTime);
    	 SMStable.SetColL(SMSColSet->ColNo(KColSMSText), aSMSText);	 	    
        		//writeStream.OpenL(table, SMSColSet->ColNo(KColSMSText));
        		//writeStream.WriteL(aSMSText);
    	 	);
    
    
    	 
    	 if(error!=KErrNone)
    	    {
    	 	return error;
    	    }
    		
    	 //writeStream.Close();
    
    	 TRAP(err, SMStable.PutL());  
    		if(err!=KErrNone)
    	 {
    	 	return err;
    	 }   
    		
    		 User::InfoPrint(_L("Record Inserted"));
    		 User::After(2000000);
    	 
    	 CleanupStack::PopAndDestroy(SMSColSet);
    	 SMStable.Close();
    		
    	 return KErrNone;
    }

  4. #4
    Regular Contributor
    Join Date
    May 2010
    Posts
    152

    Re: Problem in Opening Table

    Hi,

    Please anybody reply what is the problem in my code, or what other possible reasons of the the problem... I am stuck badly.

    Regards,
    Ravi Soni

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Problem in Opening Table

    Can it happen that you have multiple KSMSTableName literals, with different content?
    Is iMobileNannyDb kept open after CreateDatabaseL or do you close and re-open it prior to using AddSMStWithCppApiL?

  6. #6
    Regular Contributor
    Join Date
    May 2010
    Posts
    152

    Re: Problem in Opening Table

    Quote Originally Posted by wizard_hu_ View Post
    Can it happen that you have multiple KSMSTableName literals, with different content?
    Is iMobileNannyDb kept open after CreateDatabaseL or do you close and re-open it prior to using AddSMStWithCppApiL?
    Hi wizard_hu_,

    There is only one literal by name 'KSmsTableName' and

    I am manually closing the database after using CreateDatabaseL and re-open it before opening the table.

    Following is the code to open and close the database.

    // Function to open the database
    TInt CDatabaseHandler::OpenDb()
    {
    //Close();

    if(!BaflUtils::FileExists(iFsSession, KDbName))
    {
    return KErrNotFound;
    }

    TRAPD(error,
    iFileStore = CPermanentFileStore::OpenL(iFsSession, KDbName,
    EFileRead|EFileWrite);
    iFileStore->SetTypeL(iFileStore->Layout());/* Set file store type*/
    iMobileNannyDb.OpenL(iFileStore,iFileStore->Root())
    );
    if(error!=KErrNone)
    {
    return error;
    }

    iOpen = ETrue;
    User::InfoPrint(_L("DB Opened"));
    User::After(1000000);
    return KErrNone;
    }
    // Function to close the database
    TInt CDatabaseHandler::Close()
    {
    iMobileNannyDb.Close();
    if(iFileStore)
    {
    delete iFileStore;
    iFileStore = NULL;
    }
    iOpen = EFalse;
    User::InfoPrint(_L("DB Closed"));
    return KErrNone;
    }

  7. #7
    Regular Contributor
    Join Date
    May 2010
    Posts
    152

    Re: Problem in Opening Table

    Hi wizard_hu_,

    I have found the bug in the code and have rectified also... thanks for ur help.

    Regards,
    Ravi Kumar

Similar Threads

  1. Table clone problem
    By esaul in forum Symbian
    Replies: 2
    Last Post: 2010-03-25, 21:21
  2. Problem inserting data into an existing database table
    By madhukv in forum Mobile Java General
    Replies: 2
    Last Post: 2009-08-03, 11:16
  3. Problem in table model in netbeans
    By nanditasaini in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2008-02-02, 11:17
  4. Database Server - problem accessing table names
    By ash_bhatia in forum Symbian
    Replies: 2
    Last Post: 2004-03-24, 18:54
  5. Problem with IAP Table
    By jordy in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2004-03-05, 16:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×