TSqlScalarFullSelectQuery interface is used for executing SELECT sql queries, which return a single row consisting of a single column value.
Examples.
CASE 1 - retrieving records count of a table:
RSqlDatabase db;
//initialize db object....
.......
TSqlScalarFullSelectQuery fullSelectQuery(db);
TInt recCnt = fullSelectQuery.SelectIntL(_L("SELECT COUNT(*) FROM PersonTbl"));
CASE 2 - retrieving specific column value using a condition in the SELECT statement:
RSqlDatabase db;
//initialize db object....
.......
TSqlScalarFullSelectQuery fullSelectQuery(db);
TInt personId = fullSelectQuery.SelectIntL(_L("SELECT ID FROM PersonTbl WHERE Name = 'John'"));
CASE 3 - retrieving a text column value, the receiving buffer is not big enough:
RSqlDatabase db;
//initialize db object....
.......
TSqlScalarFullSelectQuery fullSelectQuery(db);
HBufC* buf = HBufC::NewLC(20);
TPtr name = buf->Des();
TInt rc = fullSelectQuery.SelectTextL(_L("SELECT Name FROM PersonTbl WHERE Id = 1"), name);
TEST(rc >= 0); //the function may return only non-negative values
if(rc > 0)
{
buf = buf->ReAllocL(rc);
CleanupStack::Pop();
CleanupStack::PushL(buf);
name.Set(buf->Des());
rc = fullSelectQuery.SelectTextL(_L("SELECT Name FROM PersonTbl WHERE Id = 1"), name);
TEST(rc == 0);
}
CleanupStack::PopAndDestroy();//buf
RSqlDatabase