I notice that ISQL is able to get the line number that an error was found on when running bad SQL. What ODBC API calls does it use to achieve this?
With other databases you would use a combination of SQLGetDiagRec and SQLGetDiagField. This doesn't seem to be the case for SQL Anywhere.
Error message from Interactive SQL... How does it know that the error is on line 4 column 1
While DBISQL does parse its input to determine the rudiments of the input SQL syntax, DBISQL has no idea precisely where an error in a statement or procedure occurred - only the server does. There is no specific mechanism for the server to return a line number or statement offset when an SQL statement is rejected, short of the error message itself. This is true with both JDBC/ODBC and with jConnect.
What you're seeing in DBISQL V7 is an estimate from DBISQL as to where the error occurred. That estimate, in your case, is simply the last line of the input. If you connect the V7 DBISQL client to a Version 11 server, try the following statement:
and you'll see that DBISQL again reports the error on line 4, column 1 (the last line of the input) but the server message (properly) says
Error -131: Syntax error near 'flum' on line 3
If using the iAnywhere Type 1 driver, which uses ODBC underneath JDBC, DBISQL (eventually) causes the issuing of an ODBC SQLGetDiagRecW() call (the "W" denoting the unicode version) to get error information on a statement. You can see this sequence if using the Type 1 JDBC driver and enable ODBC tracing. Here is an example:
In a DBISQL window, I code the (erroneous) procedure
and press F9. The error "Syntax error near ';' on line 4" is returned to DBISQL. The ODBC trace reveals:
The SQLGetDiagRecW() call returns the complete error message in the first call. The error message itself is generated by the server - there is no separate parameter returned that indicates the line number the error occurred on.
Note the (NYI) seemingly returned by ODBC is a result of using the unicode variant of SQLGetDiagRec() - the ODBC trace can't handle unicode arguments, so the output tends to get garbled in the trace.
answered 20 Apr '10, 16:00