Page 1 of 1

How to determine object is fetched or not.

PostPosted: Wed Feb 15, 2012 5:37 am
by magicu
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.

Re: How to determine object is fetched or not.

PostPosted: Wed Feb 15, 2012 8:31 am
by QxOrm admin
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