×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    246

    Can't add data to database

    Hi,

    I create a database and try to add some data. When i open the database it is empty. I don't now why. What's wrong with the code?

    First, I read name, number and key for database. Name and number are from contact database.
    Code:
    void CSMSExampleAddressContainer::GetContact(TBool aContactMode)
    {
          TInt selectedIndex = iAddListBox->CurrentItemIndex();
    
          _LIT(KKey1, "123456");
          TBuf<50> KNum;
          TBuf<50> KName;
          TBuf<50> KKey(KKey1);
    
          KNum = (*iNumberArray)[selectedIndex];    // Get contact number
          KName = (*iTextArray)[selectedIndex];     // Get contact name
    
          if ( aContactMode == ETrue )    // If user select "Send Selection"
          {
              // Display dialog to confirm handshake.
              _LIT(KSendMessage, "You've selected ");
              _LIT(KDot, ".");
              TBuf<50> textMessage;
              textMessage.Append( KSendMessage );
              textMessage.Append( KName );
              textMessage.Append( KDot );
    
              // try to display contact number based on contact name
              CAknNoteDialog* note = new (ELeave) CAknNoteDialog (CAknNoteDialog::EConfirmationTone);
              note->PrepareLC(R_CONFIRMATIONNOTE_DISPLAY_NOTE);
              note->SetTextL (textMessage);
              if ( note->RunLD() )
              {
                  // If Yes then send name, number and key to recipient
                  iAddressView->AddHandshakeL(KName, KNum, KKey);
              }
          }
    }
    Code:
    void CSMSExampleAddressView::AddHandshakeL(const TDesC& aName, const TDesC& aPhone, const TDesC& aKey)
        {
    
        _LIT(KErrorMsg,"Failed. Make sure the fields are not empty.");
        TInt err(KErrNone);
    
        // Lengths are from DBEngine.h. Author uses default length (50)
        TBuf<50> iName;
        TBuf<50> iPhone;
        TBuf<50> iPublickey;
    
        iName = aName;
        iPhone = aPhone;
        iPublickey = aKey;
    
        // add handshake using CppApi
        err = iHandshakeDb->AddHandshakeWithCppApi(iName, iPhone, iPublickey);
    
        if(err)
            ShowNoteL(KErrorMsg);
        }
    
    TInt CBookDb::AddBookWithSql(const TDesC& aAuthor,
                             const TDesC& aTitle,
                             const TDesC& aDescription)
        {
    
        if(aAuthor.Length()==0 || aTitle.Length()==0 || aDescription.Length()==0)
            {
            return KErrGeneral;
            }
    
    	_LIT(KSelect, "SELECT ");
    	_LIT(KFrom, " FROM ");
    	_LIT(KOrderBy, " ORDER BY ");
    	_LIT(KDot, ", ");
    
        // Sql: SELECT Author, Title, Description FROM Books ORDER BY Title, Author
        TBuf<KCustomSqlMaxLength> sqlStr;
        
        sqlStr.Append(KSelect);
        sqlStr.Append(KBooksAuthorCol);
        sqlStr.Append(KDot);
        sqlStr.Append(KBooksTitleCol);
        sqlStr.Append(KDot);
        sqlStr.Append(KBooksDescriptionCol);
        sqlStr.Append(KFrom);
        sqlStr.Append(KBooksTable);
        sqlStr.Append(KOrderBy);
        sqlStr.Append(KBooksTitleCol);
        sqlStr.Append(KDot);
        sqlStr.Append(KBooksAuthorCol);
    
        RDbView view;    // Create a view on the database
        TInt error;
        error = view.Prepare(iBookDb, TDbQuery(sqlStr, EDbCompareFolded));
        if(error!=KErrNone)
        {
        	return error;
        }
        error = view.EvaluateAll();
        if(error!=KErrNone)
        {
        	return error;
        }
        RDbColWriteStream writeStream;  // Use stream to insert the description
        
        TRAP(error,
        	view.InsertL();  // Insert a row. Column order matches sql select statement
        	view.SetColL(1, aAuthor);
       	 	view.SetColL(2, aTitle);
        	writeStream.OpenL(view, 3);
        	writeStream.WriteL(aDescription);
        	
        	);
        if(error!=KErrNone)
        {
        	return error;
        }
        writeStream.Close();
        TRAP(error, view.PutL()); // Complete insertion
    	if(error!=KErrNone)
        {
        	return error;
        } 
        view.Close();
        return KErrNone;
        }

    Need advice. Thanks..
    Regards,
    Nini

  2. #2
    Regular Contributor
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    246

    Unhappy Re: Can't add data to database

    Hi,

    I found that program is crash when it try to pass value to AddHandshakeWithCppApi(...). Am I passing empty values?


    void CSMSExampleAddressView::AddHandshakeL(const TDesC& aName, const TDesC& aPhone, const TDesC& aKey)
    {

    _LIT(KErrorMsg,"Failed. Make sure the fields are not empty.");
    TInt err(KErrNone);

    // Lengths are from DBEngine.h. Author uses default length (50)
    TBuf<50> iName;
    TBuf<50> iPhone;
    TBuf<50> iPublickey;

    iName = aName;
    iPhone = aPhone;
    iPublickey = aKey;

    // add handshake using CppApi
    err = iHandshakeDb->AddHandshakeWithCppApi(iName, iPhone, iPublickey); // CRASH HERE!!!
    if(err)
    {
    ShowNoteL(KErrorMsg);
    }
    }

    Need help. thanks...
    Regards,
    Nini

  3. #3
    Super Contributor
    Join Date
    Aug 2005
    Location
    india
    Posts
    2,078

    Re: Can't add data to database

    hi,

    can u paste the definition of ur function

    AddHandshakeWithCppApi

    so that we can know wht ur doing inside this function which is raising a panic.

    Thanks and Regards,
    Mateen Maldar M
    "Whatever the mind can conceive and believe, the mind can achieve"

  4. #4
    Regular Contributor
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    246

    Re: Can't add data to database

    Hi,

    Sorry, I gave the wrong code before. Here is the code for AddHandshakeWithCppApi:


    Code:
    TInt CHandshakeDb::AddHandshakeWithCppApi(const TDesC& aName, const TDesC& aPhone,
                                              const TDesC& aPublicKey)
        {
    
        if(aName.Length()==0 || aPhone.Length()==0 || aPublicKey.Length()==0)
            {
            return KErrGeneral;
            }
    
        // Create an updateable database table object
        RDbTable table;
        TInt err = table.Open(iHandshakeDb, KHandshakeTable, table.EUpdatable);
    
        if(err!=KErrNone)
        {
                return err;
        }
    
        CDbColSet* handshakeColSet = table.ColSetL();
        CleanupStack::PushL(handshakeColSet);
    
        table.Reset();
        //RDbColWriteStream writeStream;
    
        TRAPD ( error,
                table.InsertL();
                table.SetColL(handshakeColSet->ColNo(KContactNameCol), aName);      // col = 1
                table.SetColL(handshakeColSet->ColNo(KContactNumberCol), aPhone);   // col = 2
                table.SetColL(handshakeColSet->ColNo(KPublicKeyCol), aPublicKey);   // col = 3
              );
    
            if(error!=KErrNone)
        {
                return error;
        }
            //writeStream.Close();
    
        TRAP(err, table.PutL());    // Complete changes (the insertion)
            if(err!=KErrNone)
        {
                return err;
        }
    
        CleanupStack::PopAndDestroy(handshakeColSet);
        table.Close();
    
        return KErrNone;
        }
    Regards,
    Nini

Similar Threads

  1. Replies: 0
    Last Post: 2006-06-05, 18:08
  2. InsertL in database Controls the DB
    By Blkangel in forum Symbian
    Replies: 5
    Last Post: 2004-01-13, 15:02
  3. What is the real problem to receive data calls with Nokia TDMA cell modem?
    By jackal_jr in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2002-12-04, 16:05
  4. Replies: 0
    Last Post: 2002-12-04, 15:46

Posting Permissions

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