Martijn Faassen wrote:
Hi there,
I just spent several hours scratching my head over why a piece of code didn't work. I was experimenting with Mapi and tried the example listed on the top of this page:
http://monetdb.cwi.nl/TechDocs/APIs/Mapi/C/index.html
This contains the following line:
if ((hdl = mapi_query(dbh, "create table emp(name varchar, age int)")) == NULL) die(dbh);
Unfortunately, it needs to be 'varchar(20)', not just plain 'varchar'. Just 'varchar' apparently does *not* result in an error, but instead all subsequent insert operations plus the select operation do nothing whatsoever; the fetching returns no results at all.
This is weird, because I once added a very explanatory error message for this situation. Using JDBC it seems this message is indeed generated: % JdbcClient -hlocalhost Connection warning: database specifier not supported on this server (mserver_sql), protocol version 4 Welcome to the MonetDB interactive JDBC terminal! Database: MonetDB 4.8.0_rc1 Driver: MonetDB Native Driver 1.2 (Blunt) Type \q to quit, \h for a list of available commands auto commit mode: on monetdb-> create table emp(name varchar, age int); Error: CHARACTER VARYING needs a mandatory length specification in: "create table emp(name varchar," monetdb-> So, I suspect the code sample to be faulty or the error reporting not to be optimal in this case for MAPI. Additionally, all subsequent inserts are bound to fail, but not silently. If you use auto commit mode, then you would get an error: monetdb-> insert into emp values ('bla', 300); Error: Inserting into non existing table emp otherwise, if you would have a transaction, the following error would arise: monetdb-> start transaction; auto commit mode: off monetdb-> 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) monetdb-> insert into emp values ('bla', 300); Error: current transaction is aborted (please ROLLBACK) monetdb-> rollback; auto commit mode: on monetdb-> There is always an error, but it simply doesn't reach you. I'm no MAPI expert. Sjoerd might see what's the problem here for this example. I included Sjoerd in the CC of this message.
The combination of this very bad error reporting and the mistake in the very first example given on the C API page cost me quite a bit of time, so I'm slightly grumpy. :)
I will fix the example on the website in CVS. Thanks.
The bad example given is not good, but the way the error appears to be completely ignored is worse; this is not good for debuggability. The combination is terrible and not particularly conductive to the uptake of MonetDB.
It may be of course that this bug is already fixed in CVS; I'm working off the latest release.
Anyway, now that my test code finally works, I can hopefully make some progress hooking up XQuery to a Python API. (this is an experiment, and I realize the existing Python Mapi client code already ought to work, but we'll see..).
Good luck!