×
Namespaces

Variants
Actions

Archived:How to read/write long text in RDbStoreDatabase

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
CompatibilityArticle
Created: AbuElElla (15 Jul 2009)
Last edited: hamishwillee (28 Jun 2012)

Contents

Compatibility:

3rd Edition

Brief

If you want to store text in RDbStoreDatabase, we use EDbColText8 or EDbColText16 as a data type for the database column So in creating column we write TDbCol dbColumn(KColumnName, EDbColText16); But these data types are valid for only “0 to 256 characters”

For long text we use EDbColLongText8 and EDbColLongText16 So in creating column we write TDbCol dbColumn(KColumnName, EDbColLongText16); This valid for range 0 to 2^31 characters


How to Write

To set text in specific row:

_LIT(KSelectSql, "Select * From mytable");
 
TBuf<255> sqlQuery;
sqlQuery.Copy(KSelectSql);
 
RDbView dbView;
User::LeaveIfError( dbView.Prepare(iDatabase, TDbQuery(sqlQuery, EDbCompareNormal)) );
User::LeaveIfError( dbView.EvaluateAll() );
 
//get set of columns
CDbColSet* colSet = dbView.ColSetL();
 
//Insert new row
dbView.InsertL();
 
// aText is the long text
dbView.SetColL(colSet->ColNo(KColumnName), aText);
 
//commit the insertion
dbView.PutL();
 
//Close view
dbView.Close();
 
iDatabase.Compact();
 
delete colSet;

How to Read

To read the text, this is a long text it must be read using the streams

_LIT(KSelectSql, "Select * From mytable");
TBuf<255> sqlQuery;
sqlQuery.Copy(KSelectSql);
RDbView dbView;
User::LeaveIfError( dbView.Prepare(iDatabase, TDbQuery(sqlQuery, EDbCompareNormal)) );
User::LeaveIfError( dbView.EvaluateAll() );
 
//get set of columns
CDbColSet* colSet = dbView.ColSetL();
 
dbView.FirstL();
dbView.GetL();
 
RDbColReadStream stream;
stream.OpenL(dbView, colSet->ColNo(KTafseerTable_AyaTafseerCol));
 
//Every line in my database is the line text and its length (length is 4 digits then the text)
TInt len;
TBuf<100> lineLenTxt;
stream.ReadL(lineLenTxt, 4);
TLex lex;
lex.Assign(lineLenTxt);
lex.Val(len);
 
stream.ReadL(aText, len);
 
stream.Close();
dbView.Close();
delete colSet;
This page was last modified on 28 June 2012, at 09:37.
33 page views in the last 30 days.
×