[GRASS-dev] DBMI parse error question

Glynn Clements glynn at gclements.plus.com
Wed Feb 28 17:18:55 EST 2007


Markus Neteler wrote:

> > [Except that db.execute completely ignores the error message returned by
> > the parser in sqlpStmt->errmsg. Actually, AFAICT, it's the DBF driver
> > which completely ignores the error message ("grep errmsg *" in
> > db/drivers/dbf comes up blank).]
> 
> I see - but I have no clue how to implement that.

The two quick options are:

1. Modify yyerror() (lib/db/sqlp/lex.l, line 246) to actually print
the error message, e.g.:

	void yyerror( char *s )
	{
		fprintf(stderr, "%s\n", s);
		..
	}

2. Modify the DBF driver (db/drivers/dbf/dbfexe.c, line 65):

    if (yyparse() != 0) {
	sqpFreeStmt(st);
	G_free ( tmpsql) ;
	append_error("SQL parser error in statement:\n%s\n", sql);
	return DB_FAILED;
    }

to include st->errmsg somewhere in the output.

However: the notion of returning an error message back to the caller
is flawed. If the parser performed error recovery (rather than
aborting at the first error), you could get multiple error messages
for a single SQL statement (e.g. one for each invalid column
definition). In that case, making yyerror() simply print the message
to stderr (as r.mapcalc's parser does) would be preferred.

OTOH, if lib/db/sqlp is supposed to be a general-purpose SQL parser
library, a hard-coded error handling which prints to stderr might not
be desirable. In that case, you would probably want to use a callback.

As is often the case, deciding what to do is harder than actually
doing it.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list