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
simon_hain
Posts: 16,139
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
Accepted Solution

Working with SqlDataAccess?

I am referring to the "Quotes" sample app on https://github.com/blackberry/Cascades-Samples/tree/master/quotes

 

There a SqlDataAccess object is created and execute() is called.

After that QSqlDatabase::addDatabase is called to create a "non default connection".

 

Do I have to do that as well? Or could i just work with the SqlDataAccess object? If yes, what would be the up/downsides for that?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
simon_hain
Posts: 16,139
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Working with SqlDataAccess?

It seems i can answer my question, working with SqlDataAccess seems to work fine, i only had to ensure the creation of the database with QFile.


I can write my values into the database, but i have some problems reading them, as i don't fully comprehend the QVariant return value.

I execute a sql statement that returns "2" (I use SQLite Database browser to test).

 

QVariant result = sqlDataAccess->execute("SELECT...)

How do i extract the result from the QVariant?

All the samples throw the whole thing into a listview (or use a different mechanism to query the db).

 

And how would i do it for a more complex result?

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
BlackBerry Development Advisor (Retired)
gperry
Posts: 138
Registered: ‎05-11-2012
My Device: Developer

Re: Working with SqlDataAccess?

http://qt-project.org/doc/qt-4.8/qvariant.html

 

Should give you the information you require - whole point of QVariant is that you can define it how you want using toInt, toString etc. QVariant can be used to store any type of data using the value/setValue functions.

 

Regards

Graham

Please use plain text.
Developer
simon_hain
Posts: 16,139
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Working with SqlDataAccess?

Hi Graham,

i am aware of than. But the debugger seems to be unable to tell me what is in the object, and when i call toint() on a QVariant that should contain the value '2' i get 0.

My problem is that i don't really know what the return value stored in QVariant is.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Working with SqlDataAccess?

Not really an expert in this, haven't had a need to work with QVariant. Have you tried calling {qvar}.type() to determine that it is indeed an int?
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
simon_hain
Posts: 16,139
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Working with SqlDataAccess?

I got the solution to that on the BB Jam from one of the Cascades developers, did not manage to update this post until now.

You can use qDebug() << qVariant to check what exactly is in the QVariant.
RIM also promised to update the API docs to include more advanced usecases in the sample.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.