[Monetdb-developers] mapi: how to check mil query on errors?

Sjoerd Mullender sjoerd at acm.org
Thu Aug 19 17:33:40 CEST 2004


Arjan Scherpenisse wrote:
> For SQL code, I check now with:
> 
> hdl = mapi_query(mid, "very wrong query.");
> while( mapi_next_result(hdl) ) {
>     if (mapi_result_error(hdl)) {
>         // error handling here
> 
> 
> how to do this equivalent for mil queries? Or dont we need mil queries 
> anymore?
> 
> My personal opinion is to keep doing it the old way for mil-type queries 
> (if (mapi_error()) etc), but that does not seem to work...
> 

This code is not correct.  After mapi_query you're already at the first 
result set, so you should start with calling mapi_result_error.

The suggested code is:

mapi_query(hdl, query);
do {
     if ((error = mapi_result_error(hdl)) != NULL)
         mapi_explain_result(hdl, stderr);
     while ((line = mapi_fetch_line(hdl)) != NULL)
         /* use output */;
} while (mapi_next_result(hdl) == 1);

Note the comparison with 1.  MERROR is also != 0, but you shouldn't 
continue after you got an error.

(Also note the use of traditional C comment markers ;-)

-- 
Sjoerd Mullender <sjoerd at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 374 bytes
Desc: OpenPGP digital signature
URL: <http://www.monetdb.org/pipermail/developers-list/attachments/20040819/c2e82c61/attachment.sig>


More information about the developers-list mailing list