Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 49
Registered: ‎11-11-2012
My Device: z10 LE
My Carrier: Digi
Accepted Solution

Qvariant (SqlDataAccess) result to values

Hi,

 

am using SqlDataAccess to perform sqlite query and am curious what method to extract the value I am interested with e.g.

 

QVariant(QVariantList, (QVariant(QVariantMap, QMap(("max(id)", QVariant(qlonglong, 5) ) )  ) )  ) 

 in the code example (result from the query), wish to extract the "5" which is the largest ID in the table.

 

thanks,

James Tan



James Tan
Eating my dog food - TripLogger, my 1st bb10 app.
Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon

Re: Qvariant (SqlDataAccess) result to values

For details on how to use SqlDataAccess you should look at the Quotes sample app...


Read my thoughts on BlackBerry Development at news.ebscer.com
Developer
Posts: 49
Registered: ‎11-11-2012
My Device: z10 LE
My Carrier: Digi

Re: Qvariant (SqlDataAccess) result to values

I scanned through the sample app "Quotes" but can't figured where it does in C++/QT code to extract specific data.

 

From the way I read the output...it is a single result (QVariantList) so I need some method to dig into the data...any idea?



James Tan
Eating my dog food - TripLogger, my 1st bb10 app.
Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon

Re: Qvariant (SqlDataAccess) result to values

[ Edited ]

In terms of drilling down to specific data I usually write my own additional methods that take a string argument and then execute an SQL query with a where clause. For example

 

QVariantList DbHelper::getNewList(const QString group_name)
{
	QVariantList sqlData;

	mDbNameWithPath = "data/data.db";
	SqlDataAccess sqlDataAccess(mDbNameWithPath);
	sqlData = sqlDataAccess.execute("select * from MTData WHERE group_name=\""+group_name+"\"").value<QVariantList>();

	return sqlData;
}

 In terms of seeing the data in QML, I am usually just outputing to a GroupDataModel and displaying a ListView. However it is possible to parse out the components from the QVariantList. In the following code the _App.getGroupNames() method is returning a QVarientList of unique group_name values in an SQL table. Then I itterate over the list and extract each of the individual group_name values as a string.

 

var qlist = _App.getGroupNames()
if(qlist.length>0)
{
    for (var i=0;i<qlist.length;i++)
    {
        var temp = String(qlist[i].group_name)
    }
}

 


Read my thoughts on BlackBerry Development at news.ebscer.com
Developer
Posts: 49
Registered: ‎11-11-2012
My Device: z10 LE
My Carrier: Digi

Re: Qvariant (SqlDataAccess) result to values

Thanks Ebscer.

 

Managed to rig up a the method to obtain the specific value required with your concept.

Used:

1. Working with SQL- setup groupdatamodel

2. Enumerate data - QMapIterator in C++

 

thanks!



James Tan
Eating my dog food - TripLogger, my 1st bb10 app.