How to determine object is fetched or not.

Forum for posting problems using QxOrm library

How to determine object is fetched or not.

Postby magicu » Wed Feb 15, 2012 5:37 am

SettingPtr settingPtr(new Setting());
settingPtr->id = myId;

QSqlError daoError = qx::dao::fetch_by_id(settingPtr);

If myId is invalid, how to determine settingPtr is fetched or not. "settingPtr->get()" is always true. But settingPtr is invalid when myId is invalid.
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

Re: How to determine object is fetched or not.

Postby QxOrm admin » Wed Feb 15, 2012 8:31 am

Hi,

If myId is invalid, how to determine settingPtr is fetched or not.

Just check your 'daoError' variable : it contains an error if you try to fetch an instance with an invalid id.
For example :
Code: Select all
SettingPtr settingPtr(new Setting());
settingPtr->id = invalidId;
QSqlError daoError = qx::dao::fetch_by_id(settingPtr);
if (daoError.isValid())
{
   // an error occured
   qDebug() << daoError.text();
}

For more details about QSqlError type, goto here : http://doc.qt.nokia.com/4.8-snapshot/qsqlerror.html
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 9 guests

cron