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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Native Development

Reply
Super Contributor
JeffLemon
Posts: 391
Registered: ‎01-13-2011
My Carrier: NA

SQL - get data into a QVariantList

I want to get data from my datatbase as a QVariantList using a select query.

 

So far I have:

 

QVariantList sqlData;
QSqlQuery sqlQuery(mDb);
sqlQuery.prepare("select * from users");
sqlQuery.exec();
sqlData = sqlQuery.???
return sqlData;

 How can I get all rows from the database? I only seem to find get row not rows.

 

 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Please use plain text.
Developer
simon_hain
Posts: 13,775
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: SQL - get data into a QVariantList

if i don't need the key returned i use:

 

QVariant result = sqlDataAccess->execute("SELECT * FROM users");
QVariantList list = result.value<QVariantList>();

 (you can get the values of the variants using qDebug())

 

If i need the key i use:

QSqlQuery sqlQuery(queryString, sqlDataAccess->connection());
sqlQuery.exec();
int key= sqlQuery.lastInsertId().toInt();

 

----------------------------------------------------------
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.