This is a discussion on finding the sql-statement in esql within the Informix forums, part of the Database Server Software category; --> Hi, how can I get the created sql-statement after an error. I have written an error-function and esql calls ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, how can I get the created sql-statement after an error. I have written an error-function and esql calls this function after an error (EXEC SQL WHENEVER SQLERROR CALL ...). In this function I get the errornumber and the errortext from sqlca. But where stands the last sql-statement which create this error. thanks for help Steffen |
| ||||
| Steffen Koehler wrote: > how can I get the created sql-statement after an error. I have written > an error-function and esql calls this function after an error (EXEC SQL > WHENEVER SQLERROR CALL ...). In this function I get the errornumber and > the errortext from sqlca. But where stands the last sql-statement which > create this error. It isn't available. You have to go through all sorts of chicanery to achieve that - so much so I have never actually bothered to do it. If I was going to, I'd probably grab the code from my esqlfmt program (available as part of sqlfmt from the IIUG Software Archive - it's indexed under I4GL because it also includes an I4GL cross-referencer), and use it to extract the SQL statements, and generate some corresponding code around the actual statement. Maybe: { static const char sql[] = "...sql statement found by esqlfmt code..."; EXEC SQL ...sql statement found by esqlfmt code...; if (sqlca.sqlcode != 0) err_reporter(..., sql, ..., __LINE__, __FILE__, ...); } Or something along those lines. That's simple and reliable because it is under your control. Alternatively, post-process the C code before running the C compiler, and place your error handling code inside the generated C code, using the statement text defined by ESQL/C. That's more subject to the vagaries of the code generator, though - but reduces the amount of memory required since you only have one copy of each statement instead of two. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/ |