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..





