Martijn, thanks for digging this out!!! Sjoerd, would you please take care of fixing the samples and sample code in the documentation of Mapi.mx? I hope that now this is resolved you can actually start using MonetDB. Regards, Fabian Martijn Faassen wrote:
Martijn Faassen wrote: [snip]
The code sample is quite thorough in catching any error that Mapi may return (NULL value) and then to display it. Unfortunately NULL does not appear to be returned, so no error condition is noticed.
Perhaps this is a case of:
Almost every call can fail since the connection with the database server can fail at any time. Functions that return a handle (either Mapi or MapiHdl) may return NULL on failure, or they may return the handle with the error flag set. If the function returns a non-NULL handle, always check for errors with mapi_error.
The sample code on the page is not doing this 'always checking for errors'. I shall try to modify it to do so, as it'd be good to have the sample do the right thing.
I've just done a simple modification, adding the following:
if ((error = mapi_result_error(hdl)) != NULL) { mapi_explain_result(hdl, stderr); return 0; }
and this indeed gives me the expected:
MAPI = monetdb@localhost:45123 QUERY = create table emp(name varchar, age int) ERROR = !CHARACTER VARYING needs a mandatory length specification in: "create table emp(name varchar," !current transaction is aborted (please ROLLBACK)
Because the text says:
if the function returns a non-NULL handle, always check for errors with mapi_error.
and later on says:
To check for error messages from the server, call mapi_result_error(). This function returns NULL if there was no error, or the error message if there was.
I would suggest changing the example so that indeed takes place. I'd also suggest altering the text a little so that it's clear you also should always check for mapi_result_error. Programmers like me will base their code off examples, instead of reading and understanding the text completely. :)
Thanks for the feedback!
Regards,
Martijn