Page 1 of 1

qx::dao internal error when a fetch request returns no data

PostPosted: Tue Jul 27, 2010 4:33 pm
by matthieu
Hi,

I'm very surprised to get an internal error, and even an "assert(false)" when a select() query returns no data.
I guess such data miss do not need to be an error internal to QxOrm, but should be an error handled by the calling application.

Ok, I could :
  • check with a "dao::exist" query before the "fetch", but what if the record gets deleted in between?
  • build in release mode, but I still need to work on the app, debug it, and handle weird cases like "data not in the DB"
  • only turn all asserts off, but I still need some of them

Would it be possible, or dangerous, to turn remove such asserts(), and only return a NoData error?

Thanks.

--
Matthieu

Re: qx::dao internal error when a fetch request returns no data

PostPosted: Thu Jul 29, 2010 7:29 pm
by QxOrm admin
Hi,

When you want to fetch a list of objects, you need to use : qx::dao::fetch_all().
If there is no data returned by your query, there is no assert and your collection of objects is empty.
If there is a problem during query execution, I think this is normal to have an 'assert(false)' ===> you know in debug mode that there is a problem with your database and the object binded.

When you fetch an object, you know the id of this object in database.
You need to use the function : qx::dao::fetch_by_id().
If there is no data returned by your query, your id is wrong so why do you fetch it ?
I think this is normal to have an 'assert(false)' and a 'noData' error returned by the function.

Perhaps we need to have the notion of error and warning to start or not an 'assert(false)' :
If this is just a warning (for example : no data returned by the query), we have no assert...

Re: qx::dao internal error when a fetch request returns no data

PostPosted: Fri Jul 30, 2010 10:03 am
by matthieu
Hi,

QxOrm admin wrote:When you fetch an object, you know the id of this object in database.
You need to use the function : qx::dao::fetch_by_id().

In fact I'm using qx::dat::fetch_by_query(), and in my case it may be normal there is no data returned.

QxOrm admin wrote:If there is no data returned by your query, your id is wrong so why do you fetch it ?
I think this is normal to have an 'assert(false)' and a 'noData' error returned by the function.

I agree this is an error, but no an error internal to QxOrm. With an assert(), you prevent the application from dealing with the error, the application just gets killed.

QxOrm admin wrote:Perhaps we need to have the notion of error and warning to start or not an 'assert(false)' :
If this is just a warning (for example : no data returned by the query), we have no assert...

It should be fine, yes.