Symbian
Symbian OS Library

FAQ-0528 How do I access data within an EDbColLongText DBMS column ?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: DBMS
Created: 10/19/2000 Modified: 06/12/2001
Number: FAQ-0528
Platform: ER5

Question:
How do I access data within an EDbColLongText DBMS column ?

Answer:
The only way to extract the contents of a long column from a RDbRowSet is by using an RDbColReadStream.

Similarly the RDbColWriteStream should be used to set the contents of the long column within the rowset.

Only one column in a rowset object can be opened for reading as a stream at a time, and while it is open no
column in the same rowset object may be set using RDbColWriteStream.

The following example demonstrates creating a database table, using an RDbColWriteStream to set the contents
of a long column and an RDbColWriteStream to extract the contents of a long column in a rowset.

_LIT(KComposer1, "Elgar");
_LIT(KCol1, "Artist");
_LIT(KCol2, "Notes");
_LIT(KTable, "CDs");

// Create the database table

LOCAL_C void doCreateTableL(RDbDatabase& aDatabase)
{

// Create a table definition
CDbColSet* columns=CDbColSet::NewLC();

// add the columns
columns->AddL(TDbCol(KCol1,EDbColText));
columns->AddL(TDbCol(KCol2,EDbColLongText));

// Create a table
User::LeaveIfError(aDatabase.CreateTable(KTable,*columns));

// cleanup the column set
CleanupStack::PopAndDestroy();
}


// Add data

LOCAL_C void doAddDataL(const TDesC& aDatabaseFileName)
{
_LIT(KSQLStatement,"select Artist,Notes from CDs order by Artist");

// Open the file store
CFileStore* store = CFileStore::OpenLC(fsSession,aDatabaseFileName,EFileRead|EFileWrite);

// open the database from the root stream
RDbStoreDatabase database;
database.OpenL(store,store->Root());

// create a view on the database
RDbView view;
User::LeaveIfError(view.Prepare(database,TDbQuery(KSQLStatement,EDbCompareNormal)));
User::LeaveIfError(view.EvaluateAll());

// Get the structure of rowset
CDbColSet* colSet = view.ColSetL();

// insert a row
view.InsertL();

view.SetColL(colSet->ColNo(KCol1),KComposer1); // Artist

// Use the stream
RDbColWriteStream out;
TDbColNo col = colSet->ColNo(KCol2); // Ordinal position of long column

out.OpenLC(view, col);
out.WriteL(_L("Some additional comment here."));
out.Close();

CleanupStack::PopAndDestroy(); // out

view.PutL();

// close the view
view.Close();

// close the database
database.Close();

// Do not commit store: database has taken control of commit
CleanupStack::PopAndDestroy();

delete colSet;

}

// Display the data

LOCAL_C void doShowL(RDbRowSet& aSet)
{
_LIT(KRowFormatter, "\n  %S, Notes: %S \n");

// Get the structure of the rowset
CDbColSet* colSet = aSet.ColSetL();

// iterate across the row set
for (aSet.FirstL();aSet.AtRow();aSet.NextL())
{
// retrieve the row
aSet.GetL();

// while the rowset is on this row, can use a TPtrC to
// refer to any text columns
TPtrC artist=aSet.ColDes(colSet->ColNo(KCol1));

// and a stream for long columns
RDbColReadStream in;
TDbColNo col = colSet->ColNo(KCol2); // Ordinal position of long column

TBuf<256> notes; // Buffer for out notes

in.OpenLC(aSet, col);
in.ReadL(notes, aSet.ColLength(col));
in.Close();

CleanupStack::PopAndDestroy(); // in

// Display the artist and notes
console->Printf(KRowFormatter,&artist, &notes);
}

delete colSet;

}