×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Exclamation DataBase Problem!!!

    Dear All,

    i used one database program ... to implement in the Symbian C++.
    my program running without error...
    but its not creating a table ... ?
    i dont know what's the problem in my code..
    plz any one suggest me to rectify my problem...

    see the below code..
    /**************************************************/
    //MyDBClassN.cpp
    /**************************************************/

    PHP Code:
    include "MyDBClassN.h" 


    #include <f32file.h> 
    #include <D32DBMS.H> 
    #include <APPARC.H> 
    #include <e32std.h> 
    #include <BAUTILS.H> 
    #include <e32base.h> 

      

    void CMyDBClassN::ConstructL() 

        
    User::LeaveIfError(iFsSession.Connect()); 
         
        
    TFileName DBFileName
        
    // private path with no drive on it 
        
    iFsSession.PrivatePath(DBFileName); 
         
        
    TFindFile PrivFolder(iFsSession); 
        
    // find out the drive 
        
    if(KErrNone == PrivFolder.FindByDir(DBFileNameKNullDesC)) 
        { 
            
    DBFileName.Copy(PrivFolder.File()); 
            
    DBFileName.Append(KtxDatabaseName); 
                     
            if(
    BaflUtils::FileExists(iFsSessionDBFileName)) 
            { 
                
    User::LeaveIfError(iItemsDatabase.Open(iFsSession,DBFileName)); 
                
    TExampleItem NewItem;  
                
    RArray<TExampleItemaItemArray
                 
                
    NewItem.iIndex 0;  
                
    NewItem.iName=NCol1
                
    NewItem.iValue=NCol2
                
    aItemArray.Append(NewItem); 
                
    ReadDbItemsL(aItemArray); 
            } 
            else 
            {    
    // no database exists so we make one 
                
    User::LeaveIfError(iItemsDatabase.Create(iFsSession,DBFileName)); 
                
    // and will create the onlt table needed for it 
                
    CreateTableL(iItemsDatabase); 
            } 
        } 

      
    void CMyDBClassN::CreateTableL(RDbDatabaseaDatabase)  
        { 
        
    // Create a table definition 
        
    CDbColSetcolumns=CDbColSet::NewLC(); 
         
        
    // Add Columns 
        
    TDbCol id(NCol0,EDbColInt32); 
        
    // automatic indexing for items,it is our key field. 
        
    id.iAttributes=id.EAutoIncrement
        
    columns->AddL(id);                  
         
        
    columns->AddL(TDbCol(NCol1EDbColText,100)); 
        
    columns->AddL(TDbCol(NCol2EDbColText,100)); 
         
        
    // Create a table 
        
    User::LeaveIfError(aDatabase.CreateTable(KtxtItemlist, *columns)); 
                     
        
    // cleanup the column set 
        
    CleanupStack::PopAndDestroy(columns); 

      
    void CMyDBClassN::ReadDbItemsL(RArray<TExampleItem>& aItemArray

        
    aItemArray.Reset();// first reset the array 
         
        
    TFileName QueryBuffer
        
    // just get all columns & rows 
        
    QueryBuffer.Copy(_L("SELECT * FROM ")); 
        
    QueryBuffer.Append(KtxtItemlist); 
         
        
    RDbView Myview
        
    Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); 
        
    CleanupClosePushL(Myview); 
        
    Myview.EvaluateAll(); 
        
    Myview.FirstL(); 
      
        
    // Just delete one instance of the message 
        
    while(Myview.AtRow())  
        {     
            
    Myview.GetL();         
             
            
    TExampleItem NewItem;     
            
    NewItem.iIndex Myview.ColInt(1); 
            
    NewItem.iName.Copy(Myview.ColDes(2)); 
            
    NewItem.iValue.Copy(Myview.ColDes(3)); 
             
            
    aItemArray.Append(NewItem);         
            
    Myview.NextL(); 
        }  
         
        
    CleanupStack::PopAndDestroy(1); // Myview 

      
    void CMyDBClassN::DeleteFromDatabaseL(TIntaIndex
    {     
        
    TFileName QueryBuffer
        
    QueryBuffer.Copy(_L("SELECT * FROM ")); 
        
    QueryBuffer.Append(KtxtItemlist); 
        
    QueryBuffer.Append(_L(" WHERE ")); 
        
    QueryBuffer.Append(NCol0); 
        
    QueryBuffer.Append(_L(" = ")); 
        
    QueryBuffer.AppendNum(aIndex); 
             
        
    iItemsDatabase.Begin(); 
         
        
    RDbView Myview
        
    // query buffr with index finds only the selected item row. 
        
    Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); 
        
    CleanupClosePushL(Myview); 
         
        
    Myview.EvaluateAll(); 
        
    Myview.FirstL(); 
        
    // we have autoincrement in index so it should be unique 
        // but just to make sure, we use 'while', instead of 'if' 
        
    while(Myview.AtRow())             
        {     
            
    Myview.GetL(); 
            
    Myview.DeleteL();     
            
    Myview.NextL(); 
        } 
                 
        
    CleanupStack::PopAndDestroy(1); // Myview 
        
    iItemsDatabase.Commit(); 
        
    // compacts the databse, by physicaly removig deleted data. 
        
    iItemsDatabase.Compact(); 

      
    void CMyDBClassN::UpdateDatabaseL(const TDesCaName,  
                                     const 
    TDesCaValue,  
                                              
    TIntaIndex
    {     
        
    TFileName QueryBuffer
        
    QueryBuffer.Copy(_L("SELECT * FROM ")); 
        
    QueryBuffer.Append(KtxtItemlist); 
        
    QueryBuffer.Append(_L(" WHERE ")); 
        
    QueryBuffer.Append(NCol0); 
        
    QueryBuffer.Append(_L(" = ")); 
        
    QueryBuffer.AppendNum(aIndex); 
         
        
    iItemsDatabase.Begin(); 
         
        
    RDbView Myview
        
    Myview.Prepare(iItemsDatabaseTDbQuery(QueryBuffer)); 
        
    CleanupClosePushL(Myview); 
         
        
    Myview.EvaluateAll(); 
        
    Myview.FirstL(); 
         
        if(
    Myview.AtRow())             
        {             
            
    Myview.UpdateL(); 
            
    Myview.SetColL(2aName);         
            
    Myview.SetColL(3aValue);     
            
    Myview.PutL(); 
        } 
                 
        
    CleanupStack::PopAndDestroy(1); // Myview 
        
    iItemsDatabase.Commit(); 

      
    void CMyDBClassN::SaveToDatabaseL(const TDesCaName,  
                                     const 
    TDesCaValue,  
                                              
    TIntaIndex
    {     
        
    TFileName QueryBuffer
        
    QueryBuffer.Copy(_L("SELECT * FROM ")); 
        
    QueryBuffer.Append(KtxtItemlist); 
      
        
    iItemsDatabase.Begin(); 
      
        
    RDbView Myview
        
    Myview.Prepare(iItemsDatabaseTDbQuery(QueryBuffer)); 
        
    CleanupClosePushL(Myview); 
      
        
    Myview.InsertL();  
             
        
    Myview.SetColL(2aName); 
        
    Myview.SetColL(3aValue); 
      
        
    Myview.PutL();   
         
        
    aIndex Myview.ColInt(1);// autoincrement gives us unique index. 
                 
        
    CleanupStack::PopAndDestroy(1); // Myview 
        
    iItemsDatabase.Commit(); 


    CMyDBClassN::~CMyDBClassN() 

        
    iItemsDatabase.Close(); 
        
    iFsSession.Close(); 
    }  

    /**************************************************/
    //MyDBClassAppUi.cpp
    /**************************************************/

    [PHP]
    case 
    EMyDBClassCmdAppTest
                { 
                
    mydb->ConstructL(); 
                break; 
                } 
    [/PHP]

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: DataBase Problem!!!

    the code looks good to me, so can you debug and see if there is anything going bad when you run it in the emulator.

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Re: DataBase Problem!!!

    no nothing happening in the emulator

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: DataBase Problem!!!

    Quote Originally Posted by damodharan View Post
    no nothing happening in the emulator
    What do you mean by that statement ?

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,344

    Re: DataBase Problem!!!

    Quote Originally Posted by damodharan View Post
    no nothing happening in the emulator
    How about replying to your other ongoing thread: http://discussion.forum.nokia.com/fo...d.php?t=151170 ?
    Nokia Developer Wiki Moderation team

  6. #6
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Noida, India
    Posts
    115

    Re: DataBase Problem!!!

    Hi,

    Can you debug your code using breakpoints around the code and further down.

    This will help you to give a clear picture at what line the error is taking place.

    Code:
    if(KErrNone == PrivFolder.FindByDir(DBFileName, KNullDesC))
    Thanks and Regards,
    Ravi

Similar Threads

  1. database problem
    By tallapaneni in forum Symbian
    Replies: 0
    Last Post: 2008-03-25, 07:23
  2. database problem...
    By mayankkedia in forum Symbian
    Replies: 12
    Last Post: 2004-08-25, 09:08
  3. Database Server - problem accessing table names
    By ash_bhatia in forum Symbian
    Replies: 2
    Last Post: 2004-03-24, 18:54
  4. InsertL in database Controls the DB
    By Blkangel in forum Symbian
    Replies: 5
    Last Post: 2004-01-13, 15:02
  5. problem while creating database
    By ManishPatil in forum Symbian
    Replies: 4
    Last Post: 2003-12-26, 15:33

Posting Permissions

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